Imports cmplib01
Imports FMPLib01
Imports FMPLib01.FlexMapData

Public Class CBuilder
    Inherits System.Windows.Forms.Form

    Const c_Module As String = "CBuilder"
    Const c_NewGame = 0
    Const c_OpenGame = 1
    Const c_SaveButton = 2
    Const c_seperator = 3   ' here for clarity
    Const c_PlaceButton = 4       ' these are for placing things on the map
    Const c_FreeDeployment = 5
    Const c_LocalDeployment = 6
    Const c_Boundary = 7
    Const c_Objective = 8
    Const c_selseperator = 9
    Const c_SelectChit = 10
    Const c_SelectDeployment = 11
    Const c_RemoveButton = 12
    Const c_VictoryConditions = 13
    Const c_TemporaryLabel = 15
    Const c_OOB = 16

    Private Enum PlaceMode
        NoAction = 0
        Place = 1
        FreeDeploy = 2
        LocalDeploy = 3
        SelectItem = 4
        GenericBoundary = 5
        AreaObjective = 6
        TemporaryMapLabel = 7  ' this is a label that is NOT saved in the FMP. It is saved in the cgd file.
    End Enum

    Private Enum SelectMode
        NoAction = 0
        SelectAny = 1
        SelectChit = 2
        SelectDeployment = 3
        SelectMapFeature = 4
        SelectBoundary = 5
        SelectAreaObjective = 6
    End Enum

    Private Enum IconSize
        TinyIcon = 1  '10x10
        SmallIcon = 2    '16x16
        StandardIcon = 3 '32x32
        LargeIcon = 4   '48x48
    End Enum

    Private currentGame As New cmplib01.CampaignerGameData()  ' this is the game. Yeah baby.
    'Private selectedItemKey As String = "NONE0"       ' nothing selected.
    Private bFreeDeploymentZoneStarted As Boolean = False  ' used for drawing a free deployment zone
    Private deploymentZonePath As Drawing2D.GraphicsPath  ' used to draw the path
    Private zonePathComplete As Boolean = True
    Private zoneLastpoint As Point

    Private iconWidth As Int16 = 16  ' small size
    Private iconHeight As Int16 = 16 ' small size

    Private m_iconSize As IconSize = IconSize.SmallIcon
    Private m_GameDirty As Boolean = False     ' unsaved data flag
    Private m_GameLoaded As Boolean = False
    Private m_MapValidated As Boolean = False
    'placement mode and selection mode go together. If a user's placement mode is 'SelectItem', then when he clicks on the map he will
    'select the object type that his selection mode is set to. If 'SelectAny' is the mode, it will try to find the closest item in this order:
    'chits, local deployement zones, free deployment zones, map features. Selecting an item will put its properties in the properties treeview.
    Private m_placementMode As PlaceMode = PlaceMode.SelectItem
    Private m_selectionMode As SelectMode = SelectMode.SelectAny

    Private _selectedItem As GroundChitType


    ' display options
    Private m_showZOC As Boolean = True
    Private m_showRuleRange As Boolean = False
    Friend WithEvents mnuModeratorPassword As System.Windows.Forms.MenuItem
    Private m_showLOSRange As Boolean = False
    Friend WithEvents mnuPrereq As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem
    Friend WithEvents mnuResourceConsumption As System.Windows.Forms.MenuItem

    Private randy As New Random


#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        mnuResourceConsumption.Visible = True
        mnuImportTemplate.Visible = False

#If MASTER Then
        Me.Text &= "   [MASTER]"
#End If

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents mnuMain As System.Windows.Forms.MainMenu
    Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem
    Friend WithEvents imlToolbarIcons As System.Windows.Forms.ImageList
    Friend WithEvents imlTreeviewIcons As System.Windows.Forms.ImageList
    Friend WithEvents tlbMain As System.Windows.Forms.ToolBar
    Friend WithEvents btnNew As System.Windows.Forms.ToolBarButton
    Friend WithEvents btnOpen As System.Windows.Forms.ToolBarButton
    Friend WithEvents btnSave As System.Windows.Forms.ToolBarButton
    Friend WithEvents mnuFile As System.Windows.Forms.MenuItem
    Friend WithEvents mnuNew As System.Windows.Forms.MenuItem
    Friend WithEvents mnuOpen As System.Windows.Forms.MenuItem
    Friend WithEvents mnuSave As System.Windows.Forms.MenuItem
    Friend WithEvents mnuCreate As System.Windows.Forms.MenuItem
    Friend WithEvents mnuObjectiveType As System.Windows.Forms.MenuItem
    Friend WithEvents mnuResourceType As System.Windows.Forms.MenuItem
    Friend WithEvents mnuRuleType As System.Windows.Forms.MenuItem
    Friend WithEvents mnuUnitType As System.Windows.Forms.MenuItem
    Friend WithEvents mnuTokenType As System.Windows.Forms.MenuItem
    Friend WithEvents lstFactions As System.Windows.Forms.ListBox
    Friend WithEvents sep As System.Windows.Forms.ToolBarButton
    Friend WithEvents btnPlace As System.Windows.Forms.ToolBarButton
    Friend WithEvents btnRemove As System.Windows.Forms.ToolBarButton
    Friend WithEvents btnFreeDeployment As System.Windows.Forms.ToolBarButton
    Friend WithEvents btnLocalDeployment As System.Windows.Forms.ToolBarButton
    Friend WithEvents btnselectsep As System.Windows.Forms.ToolBarButton
    Friend WithEvents btnSelectChit As System.Windows.Forms.ToolBarButton
    Friend WithEvents btnSelectDeployment As System.Windows.Forms.ToolBarButton
    Friend WithEvents tabList As System.Windows.Forms.TabControl
    Friend WithEvents tabPlacedItems As System.Windows.Forms.TabPage
    Friend WithEvents tabSelectedItemProperties As System.Windows.Forms.TabPage
    Friend WithEvents tvwPlacedItems As System.Windows.Forms.TreeView
    Friend WithEvents tvwSelectedItemProperties As System.Windows.Forms.TreeView
    Friend WithEvents stbStatus As System.Windows.Forms.StatusBar
    Friend WithEvents pnlMode As System.Windows.Forms.StatusBarPanel
    Friend WithEvents fmvMap As Campaigner.FlexMapViewCampaignBuilder
    Friend WithEvents imlFormIcons As System.Windows.Forms.ImageList
    Friend WithEvents tabDeploymentZones As System.Windows.Forms.TabPage
    Friend WithEvents pnlLastAction As System.Windows.Forms.StatusBarPanel
    Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
    Friend WithEvents tabExtended As System.Windows.Forms.TabControl
    Friend WithEvents pnlDefinedItems As System.Windows.Forms.TabPage
    Friend WithEvents obdDefined As Campaigner.ctlObjectDisplay
    Friend WithEvents pnlGameProperties As System.Windows.Forms.TabPage
    Friend WithEvents colProperty As System.Windows.Forms.ColumnHeader
    Friend WithEvents colValue As System.Windows.Forms.ColumnHeader
    Friend WithEvents lstGameProperties As System.Windows.Forms.ListView
    Friend WithEvents btnShowRuleRange As System.Windows.Forms.Button
    Friend WithEvents btnDeleteObjective As System.Windows.Forms.Button
    Friend WithEvents lstDeploymentZones As System.Windows.Forms.ListBox
    Friend WithEvents btnDeleteDeploymentZone As System.Windows.Forms.Button
    Friend WithEvents btnEditDeploymentZone As System.Windows.Forms.Button
    Friend WithEvents mnuUserPlaceableDeploymentZone As System.Windows.Forms.MenuItem
    Friend WithEvents mnuView As System.Windows.Forms.MenuItem
    Friend WithEvents mnuViewMapLabels As System.Windows.Forms.MenuItem
    Friend WithEvents mnuViewLOSRanges As System.Windows.Forms.MenuItem
    Friend WithEvents mnuViewZOCRanges As System.Windows.Forms.MenuItem
    Friend WithEvents mnuEdit As System.Windows.Forms.MenuItem
    Friend WithEvents mnuMainEditor As System.Windows.Forms.MenuItem
    Friend WithEvents mnuImportTemplate As System.Windows.Forms.MenuItem
    Friend WithEvents mnuExportTemplate As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
    Friend WithEvents mnuExit As System.Windows.Forms.MenuItem
    Friend WithEvents btnBoundary As System.Windows.Forms.ToolBarButton
    Friend WithEvents btnAreaObjective As System.Windows.Forms.ToolBarButton
    Friend WithEvents tabBoundaries As System.Windows.Forms.TabPage
    Friend WithEvents tabAreaObjectives As System.Windows.Forms.TabPage
    Friend WithEvents btnDeleteBoundary As System.Windows.Forms.Button
    Friend WithEvents btnEditBoundary As System.Windows.Forms.Button
    Friend WithEvents lstBoundaries As System.Windows.Forms.ListBox
    Friend WithEvents btnDeleteAreaObjective As System.Windows.Forms.Button
    Friend WithEvents btnEditAreaObjective As System.Windows.Forms.Button
    Friend WithEvents lstObjectives As System.Windows.Forms.ListBox
    Friend WithEvents btnVictoryConditions As System.Windows.Forms.ToolBarButton
    Friend WithEvents mnuPopie As System.Windows.Forms.ContextMenu
    Friend WithEvents mnuVictoryConditions As System.Windows.Forms.MenuItem
    Friend WithEvents mnuShowGrid As System.Windows.Forms.MenuItem
    Friend WithEvents mnuShowScale As System.Windows.Forms.MenuItem
    Friend WithEvents sooperSeperator As System.Windows.Forms.ToolBarButton
    Friend WithEvents btnLabel As System.Windows.Forms.ToolBarButton
    Friend WithEvents tabLabels As System.Windows.Forms.TabPage
    Friend WithEvents btnDeleteMapLabel As System.Windows.Forms.Button
    Friend WithEvents lstMapLabels As System.Windows.Forms.ListBox
    Friend WithEvents btnOrderOfBattle As System.Windows.Forms.ToolBarButton
    Friend WithEvents btnAdvancedProperties As System.Windows.Forms.Button
    Friend WithEvents pgdSelectedItemProperties As System.Windows.Forms.PropertyGrid
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(CBuilder))
        Dim ListViewItem1 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(New String() {"Game Name", "Unnamed"}, -1, System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)))
        Dim ListViewItem2 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(New String() {"Theater Map", "c:\..."}, -1, System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)))
        Dim ListViewItem3 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(New String() {"Turn Length", "One Day Per Turn"}, -1, System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)))
        Dim ListViewItem4 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(New String() {"Maximum Turns", "60 Turns"}, -1, System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)))
        Dim ListViewItem5 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem(New String() {"Using ZOC", "Yes"}, -1, System.Drawing.SystemColors.WindowText, System.Drawing.SystemColors.Window, New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)))
        Me.mnuMain = New System.Windows.Forms.MainMenu(Me.components)
        Me.mnuFile = New System.Windows.Forms.MenuItem
        Me.mnuNew = New System.Windows.Forms.MenuItem
        Me.mnuOpen = New System.Windows.Forms.MenuItem
        Me.mnuSave = New System.Windows.Forms.MenuItem
        Me.MenuItem5 = New System.Windows.Forms.MenuItem
        Me.mnuImportTemplate = New System.Windows.Forms.MenuItem
        Me.mnuExportTemplate = New System.Windows.Forms.MenuItem
        Me.MenuItem2 = New System.Windows.Forms.MenuItem
        Me.mnuExit = New System.Windows.Forms.MenuItem
        Me.mnuEdit = New System.Windows.Forms.MenuItem
        Me.MenuItem3 = New System.Windows.Forms.MenuItem
        Me.mnuMainEditor = New System.Windows.Forms.MenuItem
        Me.mnuModeratorPassword = New System.Windows.Forms.MenuItem
        Me.mnuView = New System.Windows.Forms.MenuItem
        Me.mnuViewMapLabels = New System.Windows.Forms.MenuItem
        Me.mnuViewLOSRanges = New System.Windows.Forms.MenuItem
        Me.mnuViewZOCRanges = New System.Windows.Forms.MenuItem
        Me.mnuShowGrid = New System.Windows.Forms.MenuItem
        Me.mnuShowScale = New System.Windows.Forms.MenuItem
        Me.MenuItem4 = New System.Windows.Forms.MenuItem
        Me.mnuPrereq = New System.Windows.Forms.MenuItem
        Me.mnuResourceConsumption = New System.Windows.Forms.MenuItem
        Me.mnuCreate = New System.Windows.Forms.MenuItem
        Me.mnuObjectiveType = New System.Windows.Forms.MenuItem
        Me.mnuResourceType = New System.Windows.Forms.MenuItem
        Me.mnuRuleType = New System.Windows.Forms.MenuItem
        Me.mnuUnitType = New System.Windows.Forms.MenuItem
        Me.mnuTokenType = New System.Windows.Forms.MenuItem
        Me.mnuUserPlaceableDeploymentZone = New System.Windows.Forms.MenuItem
        Me.imlToolbarIcons = New System.Windows.Forms.ImageList(Me.components)
        Me.imlTreeviewIcons = New System.Windows.Forms.ImageList(Me.components)
        Me.tlbMain = New System.Windows.Forms.ToolBar
        Me.btnNew = New System.Windows.Forms.ToolBarButton
        Me.btnOpen = New System.Windows.Forms.ToolBarButton
        Me.btnSave = New System.Windows.Forms.ToolBarButton
        Me.sep = New System.Windows.Forms.ToolBarButton
        Me.btnPlace = New System.Windows.Forms.ToolBarButton
        Me.btnFreeDeployment = New System.Windows.Forms.ToolBarButton
        Me.btnLocalDeployment = New System.Windows.Forms.ToolBarButton
        Me.btnBoundary = New System.Windows.Forms.ToolBarButton
        Me.btnAreaObjective = New System.Windows.Forms.ToolBarButton
        Me.btnselectsep = New System.Windows.Forms.ToolBarButton
        Me.btnSelectChit = New System.Windows.Forms.ToolBarButton
        Me.btnSelectDeployment = New System.Windows.Forms.ToolBarButton
        Me.btnRemove = New System.Windows.Forms.ToolBarButton
        Me.btnVictoryConditions = New System.Windows.Forms.ToolBarButton
        Me.sooperSeperator = New System.Windows.Forms.ToolBarButton
        Me.btnLabel = New System.Windows.Forms.ToolBarButton
        Me.btnOrderOfBattle = New System.Windows.Forms.ToolBarButton
        Me.lstFactions = New System.Windows.Forms.ListBox
        Me.tabList = New System.Windows.Forms.TabControl
        Me.tabPlacedItems = New System.Windows.Forms.TabPage
        Me.tvwPlacedItems = New System.Windows.Forms.TreeView
        Me.tabBoundaries = New System.Windows.Forms.TabPage
        Me.btnDeleteBoundary = New System.Windows.Forms.Button
        Me.btnEditBoundary = New System.Windows.Forms.Button
        Me.lstBoundaries = New System.Windows.Forms.ListBox
        Me.tabDeploymentZones = New System.Windows.Forms.TabPage
        Me.btnDeleteDeploymentZone = New System.Windows.Forms.Button
        Me.btnEditDeploymentZone = New System.Windows.Forms.Button
        Me.lstDeploymentZones = New System.Windows.Forms.ListBox
        Me.tabSelectedItemProperties = New System.Windows.Forms.TabPage
        Me.btnAdvancedProperties = New System.Windows.Forms.Button
        Me.pgdSelectedItemProperties = New System.Windows.Forms.PropertyGrid
        Me.btnDeleteObjective = New System.Windows.Forms.Button
        Me.btnShowRuleRange = New System.Windows.Forms.Button
        Me.tvwSelectedItemProperties = New System.Windows.Forms.TreeView
        Me.tabAreaObjectives = New System.Windows.Forms.TabPage
        Me.btnDeleteAreaObjective = New System.Windows.Forms.Button
        Me.btnEditAreaObjective = New System.Windows.Forms.Button
        Me.lstObjectives = New System.Windows.Forms.ListBox
        Me.tabLabels = New System.Windows.Forms.TabPage
        Me.btnDeleteMapLabel = New System.Windows.Forms.Button
        Me.lstMapLabels = New System.Windows.Forms.ListBox
        Me.fmvMap = New Campaigner.FlexMapViewCampaignBuilder
        Me.stbStatus = New System.Windows.Forms.StatusBar
        Me.pnlMode = New System.Windows.Forms.StatusBarPanel
        Me.pnlLastAction = New System.Windows.Forms.StatusBarPanel
        Me.imlFormIcons = New System.Windows.Forms.ImageList(Me.components)
        Me.tabExtended = New System.Windows.Forms.TabControl
        Me.pnlDefinedItems = New System.Windows.Forms.TabPage
        Me.obdDefined = New Campaigner.ctlObjectDisplay
        Me.pnlGameProperties = New System.Windows.Forms.TabPage
        Me.lstGameProperties = New System.Windows.Forms.ListView
        Me.colProperty = New System.Windows.Forms.ColumnHeader
        Me.colValue = New System.Windows.Forms.ColumnHeader
        Me.mnuPopie = New System.Windows.Forms.ContextMenu
        Me.mnuVictoryConditions = New System.Windows.Forms.MenuItem
        Me.tabList.SuspendLayout()
        Me.tabPlacedItems.SuspendLayout()
        Me.tabBoundaries.SuspendLayout()
        Me.tabDeploymentZones.SuspendLayout()
        Me.tabSelectedItemProperties.SuspendLayout()
        Me.tabAreaObjectives.SuspendLayout()
        Me.tabLabels.SuspendLayout()
        CType(Me.pnlMode, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.pnlLastAction, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.tabExtended.SuspendLayout()
        Me.pnlDefinedItems.SuspendLayout()
        Me.pnlGameProperties.SuspendLayout()
        Me.SuspendLayout()
        '
        'mnuMain
        '
        Me.mnuMain.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuFile, Me.mnuEdit, Me.mnuView, Me.mnuCreate})
        '
        'mnuFile
        '
        Me.mnuFile.Index = 0
        Me.mnuFile.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuNew, Me.mnuOpen, Me.mnuSave, Me.MenuItem5, Me.mnuImportTemplate, Me.mnuExportTemplate, Me.MenuItem2, Me.mnuExit})
        Me.mnuFile.Text = "&File"
        '
        'mnuNew
        '
        Me.mnuNew.Index = 0
        Me.mnuNew.Text = "New"
        '
        'mnuOpen
        '
        Me.mnuOpen.Index = 1
        Me.mnuOpen.Text = "Open"
        '
        'mnuSave
        '
        Me.mnuSave.Index = 2
        Me.mnuSave.Text = "Save"
        '
        'MenuItem5
        '
        Me.MenuItem5.Index = 3
        Me.MenuItem5.Text = "-"
        '
        'mnuImportTemplate
        '
        Me.mnuImportTemplate.Index = 4
        Me.mnuImportTemplate.Text = "Import Template"
        '
        'mnuExportTemplate
        '
        Me.mnuExportTemplate.Index = 5
        Me.mnuExportTemplate.Text = "Export Template"
        Me.mnuExportTemplate.Visible = False
        '
        'MenuItem2
        '
        Me.MenuItem2.Index = 6
        Me.MenuItem2.Text = "-"
        '
        'mnuExit
        '
        Me.mnuExit.Index = 7
        Me.mnuExit.Text = "Exit"
        '
        'mnuEdit
        '
        Me.mnuEdit.Enabled = False
        Me.mnuEdit.Index = 1
        Me.mnuEdit.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem3, Me.mnuMainEditor, Me.mnuModeratorPassword})
        Me.mnuEdit.Text = "Edit"
        '
        'MenuItem3
        '
        Me.MenuItem3.Index = 0
        Me.MenuItem3.Text = "Faction Data"
        '
        'mnuMainEditor
        '
        Me.mnuMainEditor.Index = 1
        Me.mnuMainEditor.Text = "Main Editor"
        '
        'mnuModeratorPassword
        '
        Me.mnuModeratorPassword.Index = 2
        Me.mnuModeratorPassword.Text = "Moderator Password"
        '
        'mnuView
        '
        Me.mnuView.Enabled = False
        Me.mnuView.Index = 2
        Me.mnuView.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuViewMapLabels, Me.mnuViewLOSRanges, Me.mnuViewZOCRanges, Me.mnuShowGrid, Me.mnuShowScale, Me.MenuItem4, Me.mnuPrereq, Me.mnuResourceConsumption})
        Me.mnuView.Text = "View"
        '
        'mnuViewMapLabels
        '
        Me.mnuViewMapLabels.Index = 0
        Me.mnuViewMapLabels.RadioCheck = True
        Me.mnuViewMapLabels.Text = "Map Labels"
        '
        'mnuViewLOSRanges
        '
        Me.mnuViewLOSRanges.Checked = True
        Me.mnuViewLOSRanges.Index = 1
        Me.mnuViewLOSRanges.RadioCheck = True
        Me.mnuViewLOSRanges.Text = "LOS Ranges"
        '
        'mnuViewZOCRanges
        '
        Me.mnuViewZOCRanges.Checked = True
        Me.mnuViewZOCRanges.Index = 2
        Me.mnuViewZOCRanges.RadioCheck = True
        Me.mnuViewZOCRanges.Text = "ZOC Ranges"
        '
        'mnuShowGrid
        '
        Me.mnuShowGrid.Index = 3
        Me.mnuShowGrid.RadioCheck = True
        Me.mnuShowGrid.Text = "Show Grid"
        '
        'mnuShowScale
        '
        Me.mnuShowScale.Index = 4
        Me.mnuShowScale.RadioCheck = True
        Me.mnuShowScale.Text = "Show Scale"
        '
        'MenuItem4
        '
        Me.MenuItem4.Index = 5
        Me.MenuItem4.Text = "-"
        '
        'mnuPrereq
        '
        Me.mnuPrereq.Index = 6
        Me.mnuPrereq.Text = "Prerequisite Sheet"
        '
        'mnuResourceConsumption
        '
        Me.mnuResourceConsumption.Index = 7
        Me.mnuResourceConsumption.Text = "Resource Consumption"
        Me.mnuResourceConsumption.Visible = False
        '
        'mnuCreate
        '
        Me.mnuCreate.Enabled = False
        Me.mnuCreate.Index = 3
        Me.mnuCreate.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuObjectiveType, Me.mnuResourceType, Me.mnuRuleType, Me.mnuUnitType, Me.mnuTokenType, Me.mnuUserPlaceableDeploymentZone})
        Me.mnuCreate.Text = "Create"
        '
        'mnuObjectiveType
        '
        Me.mnuObjectiveType.Index = 0
        Me.mnuObjectiveType.Text = "Installation Type"
        '
        'mnuResourceType
        '
        Me.mnuResourceType.Index = 1
        Me.mnuResourceType.Text = "Resource Type"
        '
        'mnuRuleType
        '
        Me.mnuRuleType.Index = 2
        Me.mnuRuleType.Text = "Rule Type"
        '
        'mnuUnitType
        '
        Me.mnuUnitType.Index = 3
        Me.mnuUnitType.Text = "Unit Type"
        '
        'mnuTokenType
        '
        Me.mnuTokenType.Index = 4
        Me.mnuTokenType.Text = "Token Type"
        '
        'mnuUserPlaceableDeploymentZone
        '
        Me.mnuUserPlaceableDeploymentZone.Enabled = False
        Me.mnuUserPlaceableDeploymentZone.Index = 5
        Me.mnuUserPlaceableDeploymentZone.Text = "User-Placeable Deployment Zone"
        '
        'imlToolbarIcons
        '
        Me.imlToolbarIcons.ImageStream = CType(resources.GetObject("imlToolbarIcons.ImageStream"), System.Windows.Forms.ImageListStreamer)
        Me.imlToolbarIcons.TransparentColor = System.Drawing.Color.Transparent
        Me.imlToolbarIcons.Images.SetKeyName(0, "")
        Me.imlToolbarIcons.Images.SetKeyName(1, "")
        Me.imlToolbarIcons.Images.SetKeyName(2, "")
        Me.imlToolbarIcons.Images.SetKeyName(3, "")
        Me.imlToolbarIcons.Images.SetKeyName(4, "")
        Me.imlToolbarIcons.Images.SetKeyName(5, "")
        Me.imlToolbarIcons.Images.SetKeyName(6, "")
        Me.imlToolbarIcons.Images.SetKeyName(7, "")
        Me.imlToolbarIcons.Images.SetKeyName(8, "")
        Me.imlToolbarIcons.Images.SetKeyName(9, "")
        Me.imlToolbarIcons.Images.SetKeyName(10, "")
        Me.imlToolbarIcons.Images.SetKeyName(11, "")
        '
        'imlTreeviewIcons
        '
        Me.imlTreeviewIcons.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit
        Me.imlTreeviewIcons.ImageSize = New System.Drawing.Size(16, 16)
        Me.imlTreeviewIcons.TransparentColor = System.Drawing.Color.Transparent
        '
        'tlbMain
        '
        Me.tlbMain.Buttons.AddRange(New System.Windows.Forms.ToolBarButton() {Me.btnNew, Me.btnOpen, Me.btnSave, Me.sep, Me.btnPlace, Me.btnFreeDeployment, Me.btnLocalDeployment, Me.btnBoundary, Me.btnAreaObjective, Me.btnselectsep, Me.btnSelectChit, Me.btnSelectDeployment, Me.btnRemove, Me.btnVictoryConditions, Me.sooperSeperator, Me.btnLabel, Me.btnOrderOfBattle})
        Me.tlbMain.DropDownArrows = True
        Me.tlbMain.ImageList = Me.imlToolbarIcons
        Me.tlbMain.Location = New System.Drawing.Point(0, 0)
        Me.tlbMain.Name = "tlbMain"
        Me.tlbMain.ShowToolTips = True
        Me.tlbMain.Size = New System.Drawing.Size(792, 42)
        Me.tlbMain.TabIndex = 0
        '
        'btnNew
        '
        Me.btnNew.ImageIndex = 0
        Me.btnNew.Name = "btnNew"
        Me.btnNew.Tag = "btnnew"
        Me.btnNew.Text = "New"
        '
        'btnOpen
        '
        Me.btnOpen.ImageIndex = 1
        Me.btnOpen.Name = "btnOpen"
        Me.btnOpen.Tag = "btnopen"
        Me.btnOpen.Text = "Open"
        '
        'btnSave
        '
        Me.btnSave.Enabled = False
        Me.btnSave.ImageIndex = 2
        Me.btnSave.Name = "btnSave"
        Me.btnSave.Tag = "btnsave"
        Me.btnSave.Text = "Save"
        '
        'sep
        '
        Me.sep.Name = "sep"
        Me.sep.Style = System.Windows.Forms.ToolBarButtonStyle.Separator
        '
        'btnPlace
        '
        Me.btnPlace.Enabled = False
        Me.btnPlace.ImageIndex = 3
        Me.btnPlace.Name = "btnPlace"
        Me.btnPlace.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton
        Me.btnPlace.Tag = "btnplace"
        Me.btnPlace.Text = "Place"
        '
        'btnFreeDeployment
        '
        Me.btnFreeDeployment.Enabled = False
        Me.btnFreeDeployment.ImageIndex = 4
        Me.btnFreeDeployment.Name = "btnFreeDeployment"
        Me.btnFreeDeployment.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton
        Me.btnFreeDeployment.Tag = "btnfreedeployment"
        Me.btnFreeDeployment.Text = "F Deploy"
        '
        'btnLocalDeployment
        '
        Me.btnLocalDeployment.Enabled = False
        Me.btnLocalDeployment.Name = "btnLocalDeployment"
        Me.btnLocalDeployment.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton
        Me.btnLocalDeployment.Tag = "btnlocaldeployment"
        Me.btnLocalDeployment.Text = "L Deploy"
        Me.btnLocalDeployment.Visible = False
        '
        'btnBoundary
        '
        Me.btnBoundary.Enabled = False
        Me.btnBoundary.ImageIndex = 7
        Me.btnBoundary.Name = "btnBoundary"
        Me.btnBoundary.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton
        Me.btnBoundary.Tag = "btnboundary"
        Me.btnBoundary.Text = "Boundary"
        '
        'btnAreaObjective
        '
        Me.btnAreaObjective.Enabled = False
        Me.btnAreaObjective.ImageIndex = 8
        Me.btnAreaObjective.Name = "btnAreaObjective"
        Me.btnAreaObjective.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton
        Me.btnAreaObjective.Tag = "btnareaobjective"
        Me.btnAreaObjective.Text = "Objective"
        '
        'btnselectsep
        '
        Me.btnselectsep.Name = "btnselectsep"
        Me.btnselectsep.Style = System.Windows.Forms.ToolBarButtonStyle.Separator
        Me.btnselectsep.Tag = ""
        '
        'btnSelectChit
        '
        Me.btnSelectChit.Enabled = False
        Me.btnSelectChit.ImageIndex = 5
        Me.btnSelectChit.Name = "btnSelectChit"
        Me.btnSelectChit.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton
        Me.btnSelectChit.Tag = "btnselectchit"
        Me.btnSelectChit.Text = "Sel Chit"
        '
        'btnSelectDeployment
        '
        Me.btnSelectDeployment.Enabled = False
        Me.btnSelectDeployment.Name = "btnSelectDeployment"
        Me.btnSelectDeployment.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton
        Me.btnSelectDeployment.Tag = "btnselectdeployment"
        Me.btnSelectDeployment.Text = "Sel Deploy"
        Me.btnSelectDeployment.Visible = False
        '
        'btnRemove
        '
        Me.btnRemove.Enabled = False
        Me.btnRemove.ImageIndex = 6
        Me.btnRemove.Name = "btnRemove"
        Me.btnRemove.Tag = "btnremove"
        Me.btnRemove.Text = "Remove"
        '
        'btnVictoryConditions
        '
        Me.btnVictoryConditions.Enabled = False
        Me.btnVictoryConditions.ImageIndex = 9
        Me.btnVictoryConditions.Name = "btnVictoryConditions"
        Me.btnVictoryConditions.Tag = "btnvictoryconditions"
        Me.btnVictoryConditions.Text = "Victory"
        '
        'sooperSeperator
        '
        Me.sooperSeperator.Name = "sooperSeperator"
        Me.sooperSeperator.Style = System.Windows.Forms.ToolBarButtonStyle.Separator
        '
        'btnLabel
        '
        Me.btnLabel.Enabled = False
        Me.btnLabel.ImageIndex = 10
        Me.btnLabel.Name = "btnLabel"
        Me.btnLabel.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton
        Me.btnLabel.Tag = "btnlabel"
        Me.btnLabel.Text = "Label"
        '
        'btnOrderOfBattle
        '
        Me.btnOrderOfBattle.Enabled = False
        Me.btnOrderOfBattle.ImageIndex = 11
        Me.btnOrderOfBattle.Name = "btnOrderOfBattle"
        Me.btnOrderOfBattle.Tag = "btnorderofbattle"
        Me.btnOrderOfBattle.Text = "O.O.B"
        '
        'lstFactions
        '
        Me.lstFactions.Location = New System.Drawing.Point(6, 48)
        Me.lstFactions.Name = "lstFactions"
        Me.lstFactions.Size = New System.Drawing.Size(240, 43)
        Me.lstFactions.TabIndex = 4
        '
        'tabList
        '
        Me.tabList.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.tabList.Controls.Add(Me.tabPlacedItems)
        Me.tabList.Controls.Add(Me.tabBoundaries)
        Me.tabList.Controls.Add(Me.tabDeploymentZones)
        Me.tabList.Controls.Add(Me.tabSelectedItemProperties)
        Me.tabList.Controls.Add(Me.tabAreaObjectives)
        Me.tabList.Controls.Add(Me.tabLabels)
        Me.tabList.Location = New System.Drawing.Point(3, 96)
        Me.tabList.Multiline = True
        Me.tabList.Name = "tabList"
        Me.tabList.SelectedIndex = 0
        Me.tabList.Size = New System.Drawing.Size(245, 200)
        Me.tabList.TabIndex = 5
        '
        'tabPlacedItems
        '
        Me.tabPlacedItems.Controls.Add(Me.tvwPlacedItems)
        Me.tabPlacedItems.Location = New System.Drawing.Point(4, 40)
        Me.tabPlacedItems.Name = "tabPlacedItems"
        Me.tabPlacedItems.Size = New System.Drawing.Size(237, 156)
        Me.tabPlacedItems.TabIndex = 0
        Me.tabPlacedItems.Text = "Installations"
        '
        'tvwPlacedItems
        '
        Me.tvwPlacedItems.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.tvwPlacedItems.Location = New System.Drawing.Point(0, 0)
        Me.tvwPlacedItems.Name = "tvwPlacedItems"
        Me.tvwPlacedItems.Size = New System.Drawing.Size(240, 158)
        Me.tvwPlacedItems.TabIndex = 0
        '
        'tabBoundaries
        '
        Me.tabBoundaries.Controls.Add(Me.btnDeleteBoundary)
        Me.tabBoundaries.Controls.Add(Me.btnEditBoundary)
        Me.tabBoundaries.Controls.Add(Me.lstBoundaries)
        Me.tabBoundaries.Location = New System.Drawing.Point(4, 40)
        Me.tabBoundaries.Name = "tabBoundaries"
        Me.tabBoundaries.Size = New System.Drawing.Size(237, 156)
        Me.tabBoundaries.TabIndex = 3
        Me.tabBoundaries.Text = "Boundaries"
        '
        'btnDeleteBoundary
        '
        Me.btnDeleteBoundary.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnDeleteBoundary.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnDeleteBoundary.Location = New System.Drawing.Point(80, 130)
        Me.btnDeleteBoundary.Name = "btnDeleteBoundary"
        Me.btnDeleteBoundary.Size = New System.Drawing.Size(75, 23)
        Me.btnDeleteBoundary.TabIndex = 7
        Me.btnDeleteBoundary.Text = "Delete"
        '
        'btnEditBoundary
        '
        Me.btnEditBoundary.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnEditBoundary.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnEditBoundary.Location = New System.Drawing.Point(160, 130)
        Me.btnEditBoundary.Name = "btnEditBoundary"
        Me.btnEditBoundary.Size = New System.Drawing.Size(75, 23)
        Me.btnEditBoundary.TabIndex = 6
        Me.btnEditBoundary.Text = "Edit"
        '
        'lstBoundaries
        '
        Me.lstBoundaries.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.lstBoundaries.Location = New System.Drawing.Point(0, 4)
        Me.lstBoundaries.Name = "lstBoundaries"
        Me.lstBoundaries.Size = New System.Drawing.Size(236, 108)
        Me.lstBoundaries.TabIndex = 5
        '
        'tabDeploymentZones
        '
        Me.tabDeploymentZones.Controls.Add(Me.btnDeleteDeploymentZone)
        Me.tabDeploymentZones.Controls.Add(Me.btnEditDeploymentZone)
        Me.tabDeploymentZones.Controls.Add(Me.lstDeploymentZones)
        Me.tabDeploymentZones.Location = New System.Drawing.Point(4, 40)
        Me.tabDeploymentZones.Name = "tabDeploymentZones"
        Me.tabDeploymentZones.Size = New System.Drawing.Size(237, 156)
        Me.tabDeploymentZones.TabIndex = 2
        Me.tabDeploymentZones.Text = "Deployment Zones"
        '
        'btnDeleteDeploymentZone
        '
        Me.btnDeleteDeploymentZone.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnDeleteDeploymentZone.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnDeleteDeploymentZone.Location = New System.Drawing.Point(80, 126)
        Me.btnDeleteDeploymentZone.Name = "btnDeleteDeploymentZone"
        Me.btnDeleteDeploymentZone.Size = New System.Drawing.Size(75, 23)
        Me.btnDeleteDeploymentZone.TabIndex = 4
        Me.btnDeleteDeploymentZone.Text = "Delete"
        '
        'btnEditDeploymentZone
        '
        Me.btnEditDeploymentZone.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnEditDeploymentZone.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnEditDeploymentZone.Location = New System.Drawing.Point(160, 126)
        Me.btnEditDeploymentZone.Name = "btnEditDeploymentZone"
        Me.btnEditDeploymentZone.Size = New System.Drawing.Size(75, 23)
        Me.btnEditDeploymentZone.TabIndex = 3
        Me.btnEditDeploymentZone.Text = "Edit"
        '
        'lstDeploymentZones
        '
        Me.lstDeploymentZones.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.lstDeploymentZones.Location = New System.Drawing.Point(0, 0)
        Me.lstDeploymentZones.Name = "lstDeploymentZones"
        Me.lstDeploymentZones.Size = New System.Drawing.Size(236, 108)
        Me.lstDeploymentZones.TabIndex = 0
        '
        'tabSelectedItemProperties
        '
        Me.tabSelectedItemProperties.Controls.Add(Me.btnAdvancedProperties)
        Me.tabSelectedItemProperties.Controls.Add(Me.pgdSelectedItemProperties)
        Me.tabSelectedItemProperties.Controls.Add(Me.btnDeleteObjective)
        Me.tabSelectedItemProperties.Controls.Add(Me.btnShowRuleRange)
        Me.tabSelectedItemProperties.Controls.Add(Me.tvwSelectedItemProperties)
        Me.tabSelectedItemProperties.Location = New System.Drawing.Point(4, 40)
        Me.tabSelectedItemProperties.Name = "tabSelectedItemProperties"
        Me.tabSelectedItemProperties.Size = New System.Drawing.Size(237, 156)
        Me.tabSelectedItemProperties.TabIndex = 1
        Me.tabSelectedItemProperties.Text = "Properties"
        '
        'btnAdvancedProperties
        '
        Me.btnAdvancedProperties.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.btnAdvancedProperties.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnAdvancedProperties.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnAdvancedProperties.Location = New System.Drawing.Point(7, 126)
        Me.btnAdvancedProperties.Name = "btnAdvancedProperties"
        Me.btnAdvancedProperties.Size = New System.Drawing.Size(68, 23)
        Me.btnAdvancedProperties.TabIndex = 4
        Me.btnAdvancedProperties.Text = "Advanced"
        '
        'pgdSelectedItemProperties
        '
        Me.pgdSelectedItemProperties.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.pgdSelectedItemProperties.LineColor = System.Drawing.SystemColors.ScrollBar
        Me.pgdSelectedItemProperties.Location = New System.Drawing.Point(2, 0)
        Me.pgdSelectedItemProperties.Name = "pgdSelectedItemProperties"
        Me.pgdSelectedItemProperties.Size = New System.Drawing.Size(236, 112)
        Me.pgdSelectedItemProperties.TabIndex = 3
        Me.pgdSelectedItemProperties.Visible = False
        '
        'btnDeleteObjective
        '
        Me.btnDeleteObjective.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnDeleteObjective.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnDeleteObjective.Location = New System.Drawing.Point(80, 126)
        Me.btnDeleteObjective.Name = "btnDeleteObjective"
        Me.btnDeleteObjective.Size = New System.Drawing.Size(75, 23)
        Me.btnDeleteObjective.TabIndex = 2
        Me.btnDeleteObjective.Text = "Delete"
        '
        'btnShowRuleRange
        '
        Me.btnShowRuleRange.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnShowRuleRange.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnShowRuleRange.Location = New System.Drawing.Point(160, 126)
        Me.btnShowRuleRange.Name = "btnShowRuleRange"
        Me.btnShowRuleRange.Size = New System.Drawing.Size(75, 23)
        Me.btnShowRuleRange.TabIndex = 1
        Me.btnShowRuleRange.Text = "Rule Range"
        '
        'tvwSelectedItemProperties
        '
        Me.tvwSelectedItemProperties.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.tvwSelectedItemProperties.Location = New System.Drawing.Point(0, 0)
        Me.tvwSelectedItemProperties.Name = "tvwSelectedItemProperties"
        Me.tvwSelectedItemProperties.Size = New System.Drawing.Size(236, 121)
        Me.tvwSelectedItemProperties.TabIndex = 0
        '
        'tabAreaObjectives
        '
        Me.tabAreaObjectives.Controls.Add(Me.btnDeleteAreaObjective)
        Me.tabAreaObjectives.Controls.Add(Me.btnEditAreaObjective)
        Me.tabAreaObjectives.Controls.Add(Me.lstObjectives)
        Me.tabAreaObjectives.Location = New System.Drawing.Point(4, 40)
        Me.tabAreaObjectives.Name = "tabAreaObjectives"
        Me.tabAreaObjectives.Size = New System.Drawing.Size(237, 156)
        Me.tabAreaObjectives.TabIndex = 4
        Me.tabAreaObjectives.Text = "Objectives"
        '
        'btnDeleteAreaObjective
        '
        Me.btnDeleteAreaObjective.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnDeleteAreaObjective.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnDeleteAreaObjective.Location = New System.Drawing.Point(80, 130)
        Me.btnDeleteAreaObjective.Name = "btnDeleteAreaObjective"
        Me.btnDeleteAreaObjective.Size = New System.Drawing.Size(75, 23)
        Me.btnDeleteAreaObjective.TabIndex = 7
        Me.btnDeleteAreaObjective.Text = "Delete"
        '
        'btnEditAreaObjective
        '
        Me.btnEditAreaObjective.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnEditAreaObjective.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnEditAreaObjective.Location = New System.Drawing.Point(160, 130)
        Me.btnEditAreaObjective.Name = "btnEditAreaObjective"
        Me.btnEditAreaObjective.Size = New System.Drawing.Size(75, 23)
        Me.btnEditAreaObjective.TabIndex = 6
        Me.btnEditAreaObjective.Text = "Edit"
        '
        'lstObjectives
        '
        Me.lstObjectives.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.lstObjectives.Location = New System.Drawing.Point(0, 4)
        Me.lstObjectives.Name = "lstObjectives"
        Me.lstObjectives.Size = New System.Drawing.Size(236, 108)
        Me.lstObjectives.TabIndex = 5
        '
        'tabLabels
        '
        Me.tabLabels.Controls.Add(Me.btnDeleteMapLabel)
        Me.tabLabels.Controls.Add(Me.lstMapLabels)
        Me.tabLabels.Location = New System.Drawing.Point(4, 40)
        Me.tabLabels.Name = "tabLabels"
        Me.tabLabels.Size = New System.Drawing.Size(237, 156)
        Me.tabLabels.TabIndex = 5
        Me.tabLabels.Text = "Labels"
        '
        'btnDeleteMapLabel
        '
        Me.btnDeleteMapLabel.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnDeleteMapLabel.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnDeleteMapLabel.Location = New System.Drawing.Point(152, 130)
        Me.btnDeleteMapLabel.Name = "btnDeleteMapLabel"
        Me.btnDeleteMapLabel.Size = New System.Drawing.Size(75, 23)
        Me.btnDeleteMapLabel.TabIndex = 10
        Me.btnDeleteMapLabel.Text = "Delete"
        '
        'lstMapLabels
        '
        Me.lstMapLabels.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.lstMapLabels.Location = New System.Drawing.Point(0, 4)
        Me.lstMapLabels.Name = "lstMapLabels"
        Me.lstMapLabels.Size = New System.Drawing.Size(236, 108)
        Me.lstMapLabels.TabIndex = 8
        '
        'fmvMap
        '
        Me.fmvMap.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.fmvMap.BridgeSelected = False
        Me.fmvMap.CurrentGameData = Nothing
        Me.fmvMap.FeaturePathOutlineColor = System.Drawing.Color.Yellow
        Me.fmvMap.FMPData = CType(resources.GetObject("fmvMap.FMPData"), FMPLib01.FlexMapData)
        Me.fmvMap.LabelColor = System.Drawing.Color.Yellow
        Me.fmvMap.LabelSize = CType(16, Short)
        Me.fmvMap.Location = New System.Drawing.Point(256, 48)
        Me.fmvMap.Name = "fmvMap"
        Me.fmvMap.SelectedBridge = Nothing
        Me.fmvMap.SelectedChit = Nothing
        Me.fmvMap.SelectedDeploymentZone = Nothing
        Me.fmvMap.ShowAllObjectiveRuleRanges = False
        Me.fmvMap.ShowGrid = False
        Me.fmvMap.ShowLabels = False
        Me.fmvMap.ShowLOS = True
        Me.fmvMap.ShowMapOnly = True
        Me.fmvMap.ShowPaths = False
        Me.fmvMap.ShowScale = False
        Me.fmvMap.ShowSelectedObjectiveRuleRanges = False
        Me.fmvMap.ShowZOC = True
        Me.fmvMap.Size = New System.Drawing.Size(528, 472)
        Me.fmvMap.TabIndex = 6
        Me.fmvMap.VertexColor = System.Drawing.Color.AntiqueWhite
        Me.fmvMap.VertexSize = CType(3, Short)
        '
        'stbStatus
        '
        Me.stbStatus.Location = New System.Drawing.Point(0, 523)
        Me.stbStatus.Name = "stbStatus"
        Me.stbStatus.Panels.AddRange(New System.Windows.Forms.StatusBarPanel() {Me.pnlMode, Me.pnlLastAction})
        Me.stbStatus.ShowPanels = True
        Me.stbStatus.Size = New System.Drawing.Size(792, 22)
        Me.stbStatus.TabIndex = 7
        '
        'pnlMode
        '
        Me.pnlMode.Name = "pnlMode"
        Me.pnlMode.Text = "Mode:"
        Me.pnlMode.Width = 242
        '
        'pnlLastAction
        '
        Me.pnlLastAction.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring
        Me.pnlLastAction.Name = "pnlLastAction"
        Me.pnlLastAction.Text = "Last Action:"
        Me.pnlLastAction.Width = 533
        '
        'imlFormIcons
        '
        Me.imlFormIcons.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit
        Me.imlFormIcons.ImageSize = New System.Drawing.Size(16, 16)
        Me.imlFormIcons.TransparentColor = System.Drawing.Color.Transparent
        '
        'tabExtended
        '
        Me.tabExtended.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.tabExtended.Controls.Add(Me.pnlDefinedItems)
        Me.tabExtended.Controls.Add(Me.pnlGameProperties)
        Me.tabExtended.Location = New System.Drawing.Point(4, 304)
        Me.tabExtended.Name = "tabExtended"
        Me.tabExtended.SelectedIndex = 0
        Me.tabExtended.Size = New System.Drawing.Size(244, 216)
        Me.tabExtended.TabIndex = 8
        '
        'pnlDefinedItems
        '
        Me.pnlDefinedItems.Controls.Add(Me.obdDefined)
        Me.pnlDefinedItems.Location = New System.Drawing.Point(4, 22)
        Me.pnlDefinedItems.Name = "pnlDefinedItems"
        Me.pnlDefinedItems.Size = New System.Drawing.Size(236, 190)
        Me.pnlDefinedItems.TabIndex = 1
        Me.pnlDefinedItems.Text = "Defined Items"
        '
        'obdDefined
        '
        Me.obdDefined.Location = New System.Drawing.Point(0, 0)
        Me.obdDefined.Name = "obdDefined"
        Me.obdDefined.ShowLowerGrid = False
        Me.obdDefined.Size = New System.Drawing.Size(240, 200)
        Me.obdDefined.TabIndex = 0
        '
        'pnlGameProperties
        '
        Me.pnlGameProperties.Controls.Add(Me.lstGameProperties)
        Me.pnlGameProperties.Location = New System.Drawing.Point(4, 22)
        Me.pnlGameProperties.Name = "pnlGameProperties"
        Me.pnlGameProperties.Size = New System.Drawing.Size(236, 190)
        Me.pnlGameProperties.TabIndex = 2
        Me.pnlGameProperties.Text = "Game Properties"
        '
        'lstGameProperties
        '
        Me.lstGameProperties.AutoArrange = False
        Me.lstGameProperties.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.colProperty, Me.colValue})
        Me.lstGameProperties.GridLines = True
        ListViewItem1.Tag = "gamename"
        ListViewItem2.Tag = "theatermapfilename"
        ListViewItem3.Tag = "turnlength"
        ListViewItem4.Tag = "maxturns"
        ListViewItem5.Tag = "usingzoc"
        Me.lstGameProperties.Items.AddRange(New System.Windows.Forms.ListViewItem() {ListViewItem1, ListViewItem2, ListViewItem3, ListViewItem4, ListViewItem5})
        Me.lstGameProperties.LabelWrap = False
        Me.lstGameProperties.Location = New System.Drawing.Point(0, 0)
        Me.lstGameProperties.Name = "lstGameProperties"
        Me.lstGameProperties.Size = New System.Drawing.Size(264, 192)
        Me.lstGameProperties.TabIndex = 0
        Me.lstGameProperties.UseCompatibleStateImageBehavior = False
        Me.lstGameProperties.View = System.Windows.Forms.View.Details
        '
        'colProperty
        '
        Me.colProperty.Text = "Property"
        Me.colProperty.Width = 96
        '
        'colValue
        '
        Me.colValue.Text = "Value"
        Me.colValue.Width = 139
        '
        'mnuPopie
        '
        Me.mnuPopie.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuVictoryConditions})
        '
        'mnuVictoryConditions
        '
        Me.mnuVictoryConditions.Index = 0
        Me.mnuVictoryConditions.Text = "Victory Conditions"
        '
        'CBuilder
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(792, 545)
        Me.Controls.Add(Me.tabExtended)
        Me.Controls.Add(Me.stbStatus)
        Me.Controls.Add(Me.fmvMap)
        Me.Controls.Add(Me.tabList)
        Me.Controls.Add(Me.lstFactions)
        Me.Controls.Add(Me.tlbMain)
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.Menu = Me.mnuMain
        Me.Name = "CBuilder"
        Me.Text = "Campaign Builder"
        Me.tabList.ResumeLayout(False)
        Me.tabPlacedItems.ResumeLayout(False)
        Me.tabBoundaries.ResumeLayout(False)
        Me.tabDeploymentZones.ResumeLayout(False)
        Me.tabSelectedItemProperties.ResumeLayout(False)
        Me.tabAreaObjectives.ResumeLayout(False)
        Me.tabLabels.ResumeLayout(False)
        CType(Me.pnlMode, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.pnlLastAction, System.ComponentModel.ISupportInitialize).EndInit()
        Me.tabExtended.ResumeLayout(False)
        Me.pnlDefinedItems.ResumeLayout(False)
        Me.pnlGameProperties.ResumeLayout(False)
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

    Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click
        Me.Dispose()
    End Sub

    Private Sub tlbMain_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles tlbMain.ButtonClick

        Select Case e.Button.Tag
            Case Is = "btnnew"
                NewGame()
            Case Is = "btnopen"
                OpenGame()
            Case Is = "btnsave"
                SaveExistingGame()
            Case Is = "btnplace"
                If e.Button.Pushed = True Then
                    PlacementMode = PlaceMode.Place
                Else
                    PlacementMode = PlaceMode.SelectItem
                End If
            Case Is = "btnfreedeployment"
                If e.Button.Pushed = True Then
                    PlacementMode = PlaceMode.FreeDeploy
                    zonePathComplete = True
                Else
                    PlacementMode = PlaceMode.SelectItem
                End If
            Case Is = "btnlocaldeployment"
                If e.Button.Pushed = True Then
                    PlacementMode = PlaceMode.LocalDeploy
                Else
                    PlacementMode = PlaceMode.SelectItem
                End If
            Case Is = "btnselectchit"
                If e.Button.Pushed Then
                    SelectionMode = SelectMode.SelectChit
                Else
                    SelectionMode = SelectMode.NoAction
                End If
            Case Is = "btnselectdeploymentzone"
                If e.Button.Pushed Then
                    SelectionMode = SelectMode.SelectDeployment
                Else
                    SelectionMode = SelectMode.SelectDeployment
                End If
            Case Is = "btnboundary"
                If e.Button.Pushed Then
                    PlacementMode = PlaceMode.GenericBoundary
                    zonePathComplete = True
                Else
                    PlacementMode = PlaceMode.SelectItem
                End If
            Case Is = "btnareaobjective"
                If e.Button.Pushed Then
                    PlacementMode = PlaceMode.AreaObjective
                    zonePathComplete = True
                Else
                    PlacementMode = PlaceMode.SelectItem
                End If
            Case Is = "btnremove"
                ' removes the selected item
                DeleteSelectedObjective()
            Case Is = "btnvictoryconditions"
                ShowVictoryConditions()
            Case Is = "btnlabel"
                If e.Button.Pushed Then
                    PlacementMode = PlaceMode.TemporaryMapLabel
                Else
                    PlacementMode = PlaceMode.NoAction
                End If
            Case Is = "btnorderofbattle"
                Dim fOob As New frmOOBEditor(currentGame)
                fOob.ShowDialog()

        End Select

        ' we call a redraw to clear any extraneous junk
        fmvMap.RedrawMap()

    End Sub

#Region "Save Game"
    Private Function SaveExistingGame() As Boolean
        Dim filePath As String
        Dim saveFile As New SaveFileDialog()

        Try
            If m_GameLoaded = False Then
                MsgBox("There is no current game data. You must create a new game before you save.", MsgBoxStyle.OkOnly, "No Data")
                Return False
            End If

            saveFile.Filter = "Campaigner *.cgd|*.cgd"
            saveFile.ShowDialog()

            If saveFile.FileName <> "" Then
                currentGame.Save(saveFile.FileName)
            End If
        Catch ex As Exception
            MsgBox("Save not successful.", MsgBoxStyle.OkOnly, "Not Saved")
            HandleException(c_Module, ex)
        End Try

    End Function
#End Region

#Region "Open Game"
    Private Sub OpenGame()
        ' calls open existing game. Seperate to keep the logic easy to read and extend.
        ' also maintains the gameloaded and mapvalidated properties.
        Try

            If GameLoaded = True Then
                If MessageBox.Show("You already have a game loaded, would you like to abandon the current game and load a new one?", "Load New Game", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.No Then
                    Exit Sub
                End If
            End If

            If OpenExistingGame() = False Then Exit Sub

            '// check moderator password

            Dim done As Boolean
            Do Until done
                If Not OkModeratorPassword(currentGame) Then
                    If MessageBox.Show("You have entered the incorrect password.", "Incorrect Password", MessageBoxButtons.RetryCancel) = Windows.Forms.DialogResult.Cancel Then
                        currentGame = New CampaignerGameData
                        fmvMap.CurrentGameData = currentGame
                        fmvMap.FMPData = New FlexMapData
                        fmvMap.RedrawMap()
                        Exit Sub
                    End If
                Else
                    done = True
                End If
            Loop


            fmvMap.CurrentGameData = currentGame
            ReleaseMenuLock()
            GameLoaded = True
            MapValidated = True
            PopulateGameData()
            PopulateFactionList()
            RefreshPlacedItemsTree()
            ListBoundaries()
            ListAreaObjectives()
            ListTempLabels()
            SetTitle()
            tlbMain.Buttons(c_OOB).Enabled = True
            ' generic properties
            HandleGenericPropertiesForOpen()
            fmvMap.RedrawMap()
            fmvMap.ShowMapOnly = False
        Catch ex As System.FormatException ' raised when the user doesn't select a file... presses cancel
            MsgBox("No file has been loaded.", MsgBoxStyle.OkOnly, "No File")
            GameLoaded = False
            MapValidated = False
            Exit Sub
        Catch ex As System.IO.DirectoryNotFoundException
            MsgBox(ex.Message, MsgBoxStyle.Critical, "File Missing")
            GameLoaded = False
            MapValidated = False
            Exit Sub
        Catch ex As System.IO.IOException ' errors while loading the file
            MsgBox("An error has occured while trying to load the file. Please check the file.", MsgBoxStyle.OkOnly, "File Not Loaded")
            GameLoaded = False
            MapValidated = False
            Exit Sub
        Catch ex As System.Data.DataException ' no file selected or something... could not find map... etc
            MsgBox("This game contains either no map or the map cannot be found. Please check the cgd file.", MsgBoxStyle.Critical, "Invalid Map")
            GameLoaded = False
            MapValidated = False
            Exit Sub
        Catch ex As Exception
            HandleException(c_Module, ex)
            GameLoaded = False
            MapValidated = False
        End Try
    End Sub

    Private Function OkModeratorPassword(ByRef game As CampaignerGameData) As Boolean
        If game.ModeratorPassword = "" Then Return True
        Dim pass As String = InputBox("This game is protected with a moderator password. Please enter the password to continue.", "Enter Password")
        If pass = game.ModeratorPassword Then
            Return True
        Else
            Return False
        End If
    End Function

    Private Sub HandleGenericPropertiesForOpen()
        ' handles the generic properties when opening a file
        Dim gen As GenericProperty

        For Each gen In currentGame.ExtendedProperties
            Select Case gen.PropertyName
                Case Is = "LabelType1"
                    AddTemporaryLabelToFMP(gen)
            End Select
        Next

    End Sub

    Private Sub AddTemporaryLabelToFMP(ByVal gen As GenericProperty)
        Dim lab As New FMPLib01.FlexMapData.MapLabel()
        ' use the labels function to populate its own properties. Cuz, that ro><0rz
        lab.text = "boo"
        lab.FromString(gen.PropertyValue)

        fmvMap.FMPData.TemporaryLabels.Add(lab)
        lstMapLabels.Items.Add(lab)

    End Sub

    Private Function OpenExistingGame() As Boolean
        Dim filePath As String
        Dim openFile As New OpenFileDialog()

        Try
            openFile.Filter = "Campaigner *.cgd | *.cgd"
            openFile.Multiselect = False
            openFile.ShowDialog()
            'TODO: put smarter error handling in here, this one is lame.

            If openFile.FileName <> "" Then
                Try
                    currentGame = Nothing ' KILLL AAAALLLL STUFF
                    currentGame = New cmplib01.CampaignerGameData()
                    currentGame = currentGame.Open(openFile.FileName)
                    Try
                        ' mappath is always x:\running dir\campaigns\maps\MAPNAME.FMP
                        Dim totalPath As String
                        totalPath = System.AppDomain.CurrentDomain.BaseDirectory & "\Campaigns\Maps\" & currentGame.TheaterMapFilename
                        fmvMap.OpenMap(totalPath)
                    Catch ex As System.IO.DirectoryNotFoundException
                        ' rethrow map file problems
                        Throw ex
                    Catch ex As Exception
                        Throw New System.Data.DataException()
                    End Try
                Catch ex As Exception
                    Throw ex
                End Try
            Else
                '// cancel was pressed?
                Return False
            End If

            ' populate the list of defined items.
            obdDefined.campaignerGameData = currentGame
            obdDefined.ListItems()
            Return True
        Catch ex As Exception
            HandleException(c_Module, ex)
            Return False
        End Try
    End Function

#End Region

#Region "New Game"
    Private Sub NewGame()
        currentGame = Nothing
        currentGame = New cmplib01.CampaignerGameData()

        currentGame.SetUpDataMapping()
        Dim datamap() As Byte = currentGame.SystemValue("datamap")
        datamap(221) = 0 '// non-demo

        ' set the demo state for newly created campaigns
        'currentGame.Demo = c_Demo
        currentGame.TurnLength = cmplib01.TurnLength_cgd.FullDay
        currentGame.MaxTurns = 60
        currentGame.GameName = "New Game"
        fmvMap.ShowMapOnly = False

        Try
            ShowNewCampaignForm()
            'create a moderator player
            Dim play As New Player()
            play.PlayerName = "<Moderator>"
            currentGame.Players.Add(play.PlayerName, play)

            '// add the automatic default items (in this case, deployment point resource)
            Dim depres As New DeploymentPointResource
            currentGame.ResourceTypes_g.Add(depres, depres.ResourceName)

            GameLoaded = True
            MapValidated = True
            PopulateFactionList()
            fmvMap.CurrentGameData = currentGame
            fmvMap.RedrawMap()
            PopulateGameData()
            tlbMain.Buttons(c_OOB).Enabled = True
        Catch ex As System.Data.DataException
            MsgBox("This game does not have a Theater Map. You must first select a Theater Map before this game is valid.", MsgBoxStyle.OkOnly, "Invalid Game")
            GameLoaded = True
            MapValidated = False
        Catch ex As Exception
            MsgBox("Error: '" & ex.Message & "' encountered while trying to create a new game. No game has been created.", MsgBoxStyle.OkOnly, "Error Encountered")
            GameLoaded = False
            MapValidated = False
        End Try

        SetTitle()
        ReleaseMenuLock()
    End Sub


    Private Function ShowNewCampaignForm() As Boolean
        Dim newGame As New frmNewEmptyCampaign(currentGame)
        Me.AddOwnedForm(newGame)
        newGame.ShowDialog()

        newGame.Dispose()

        ' populate the list of defined items.
        obdDefined.campaignerGameData = currentGame
        obdDefined.ListItems()

        ' map
        If currentGame.TheaterMapFilename = "none" Then
            Throw New System.Data.DataException()
        Else
            Dim totalPath As String
            totalPath = System.AppDomain.CurrentDomain.BaseDirectory & "\Campaigns\Maps\" & currentGame.TheaterMapFilename
            fmvMap.OpenMap(totalPath)
        End If

        Return (True)

    End Function
#End Region

    Private Sub ReleaseMenuLock()
        ' enables the menu items
        mnuView.Enabled = True
        mnuEdit.Enabled = True
        mnuCreate.Enabled = True
    End Sub

    Private Sub PopulateGameData()
        ' this populates the GameProperties listview
        Dim listI As New ListViewItem()
        Dim subItem As New ListViewItem.ListViewSubItem()

        lstGameProperties.Items.Clear()
        ' game name
        listI.Text = "Game Name"
        subItem.Text = currentGame.GameName
        listI.SubItems.Add(subItem)
        lstGameProperties.Items.Add(listI)
        ' theater filename
        listI = New ListViewItem()
        subItem = New ListViewItem.ListViewSubItem()
        listI.Text = "Theater Map Filename"
        subItem.Text = currentGame.TheaterMapFilename
        listI.SubItems.Add(subItem)
        lstGameProperties.Items.Add(listI)
        ' turn length
        listI = New ListViewItem()
        subItem = New ListViewItem.ListViewSubItem()
        listI.Text = "Turn Length"
        subItem.Text = currentGame.TurnLength.ToString
        listI.SubItems.Add(subItem)
        lstGameProperties.Items.Add(listI)
        ' max turns
        listI = New ListViewItem()
        subItem = New ListViewItem.ListViewSubItem()
        listI.Text = "Maximum Turns"
        subItem.Text = currentGame.MaxTurns
        listI.SubItems.Add(subItem)
        lstGameProperties.Items.Add(listI)
        ' reinforcements
        listI = New ListViewItem()
        subItem = New ListViewItem.ListViewSubItem
        listI.Text = "Allow Reinforcements"
        subItem.Text = YesOrNo(currentGame.AllowPlayerManageChits)
        listI.SubItems.Add(subItem)
        lstGameProperties.Items.Add(listI)
        ' using zoc
        listI = New ListViewItem()
        subItem = New ListViewItem.ListViewSubItem()
        listI.Text = "Using ZOC"
        subItem.Text = YesOrNo(currentGame.UsesZOC)
        listI.SubItems.Add(subItem)
        lstGameProperties.Items.Add(listI)
        ' bg max pv
        listI = New ListViewItem
        subItem = New ListViewItem.ListViewSubItem
        listI.Text = "Battlegroup Point Cap"
        subItem.Text = currentGame.BattlegroupMaxPointValue
        listI.SubItems.Add(subItem)
        lstGameProperties.Items.Add(listI)

    End Sub

    Private Function YesOrNo(ByVal boo As Boolean) As String
        If boo = False Then
            Return "No"
        Else
            Return "Yes"
        End If
    End Function

#Region "FMV Events"

    Private Sub MapClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles fmvMap.DisplayClick

        If e.Button = MouseButtons.Right Then Exit Sub

        Select Case PlacementMode
            Case PlaceMode.NoAction
                Exit Sub
            Case PlaceMode.Place
                'If selectedItemKey = "NONE0" Then Exit Sub
                If _selectedItem Is Nothing Then Exit Sub
                PlaceGroundUnit(e)

                'If selectedItemKey.Substring(0, 4) = "OBJT" Then PlaceGroundUnit(e)
                'If selectedItemKey.Substring(0, 4) = "CHTT" Then PlaceGroundUnit(e)
                'If selectedItemKey.Substring(0, 4) = "TOKT" Then PlaceGroundUnit(e)
            Case PlaceMode.FreeDeploy
                If zonePathComplete = True Then
                    BeginNewPath(e)
                Else
                    ContinuePath(e)
                End If
                fmvMap.DrawFeaturePath(deploymentZonePath, Color.Red, Color.Black, 1)
            Case PlaceMode.GenericBoundary
                If zonePathComplete = True Then
                    BeginNewPath(e)
                Else
                    ContinuePath(e)
                End If
                fmvMap.DrawFeaturePath(deploymentZonePath, Color.Blue, Color.Black, 1)
            Case PlaceMode.AreaObjective
                If zonePathComplete = True Then
                    BeginNewPath(e)
                Else
                    ContinuePath(e)
                End If
            Case PlaceMode.LocalDeploy

            Case PlaceMode.SelectItem
                Dim pnt As Point
                Select Case SelectionMode
                    Case SelectMode.SelectChit
                        pnt.X = e.X
                        pnt.Y = e.Y
                        SelectChit(pnt)
                    Case SelectMode.SelectDeployment
                End Select
            Case PlaceMode.TemporaryMapLabel
                ' wesa add a new label... its gut!
                AddLabel(e)
        End Select
    End Sub

    Private Sub AddLabel(ByVal e As MouseEventArgs)

        Try
            Dim lab As New CampaignerLabel
            Dim fNewLab As New frmNewTempLabel(lab)
            fNewLab.ShowDialog()

            If Not fNewLab.Cancelled Then
                ' add it to the map's temporary labels collection and to the generic properties
                lab.location = New Point(e.X, e.Y)

                '// sanity check to make sure clabels is created
                If currentGame.cLabels Is Nothing Then currentGame.cLabels = New CampaignerLabels
                currentGame.cLabels.Add(lab)

                ' if we are showing labels, draw them baby!
                If fmvMap.ShowLabels Then fmvMap.RedrawMap()
                lstMapLabels.Items.Add(lab)
            End If
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

    End Sub

    Private Sub ListTempLabels()
        Try
            lstMapLabels.Items.Clear()
            '// 1.0.2.0 brings in labels properly now.
            If currentGame.cLabels Is Nothing Then currentGame.cLabels = New CampaignerLabels
            For Each clab As CampaignerLabel In currentGame.cLabels
                lstMapLabels.Items.Add(clab)
            Next
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

        'Dim mapLaB As FMPLib01.FlexMapData.MapLabel
        'For Each mapLaB In fmvMap.FMPData.TemporaryLabels
        '    lstMapLabels.Items.Add(mapLaB)
        'Next

    End Sub

    Private Sub MapEnterPressed() Handles fmvMap.EnterPressed
        If zonePathComplete = False Then
            ClosePath()
        End If
    End Sub

    Private Sub fmvMap_ObjectiveSelected() Handles fmvMap.ObjectiveSelected
        ShowObjectiveProperties(fmvMap.SelectedChit)
    End Sub

#End Region

    Private Sub PopulateFactionList()
        lstFactions.Items.Clear()

        Try
            Dim de As DictionaryEntry
            Dim sKey As String
            Dim i As Int16

            For Each de In currentGame.Faction_g.HT
                sKey = de.Key.ToString

                lstFactions.Items.Add(currentGame.Faction_g.HT.Item(sKey))
            Next

            ' select the first faction in the list
            lstFactions.SelectedIndex = 0

        Catch ex As Exception
            ' I don't expect any exceptions, so...
            HandleException(c_Module, ex)
        End Try

    End Sub

    Private Sub RefreshPlacedItemsTree()

        'clear tree
        tvwPlacedItems.Nodes.Clear()

        Dim mem As ChitMember
        For Each mem In currentGame.Chits
            Dim nod As New TreeNode(mem.Name)
            If mem.OwningFaction.FactionID = currentGame.selectedFaction.FactionID Then
                nod.ForeColor = Color.DarkGreen
            Else
                nod.ForeColor = Color.DarkRed
            End If

            With nod.Nodes
                .Add("Type: " & mem.UnitType.ToString)
                'TODO: put in the proper dataatatttea....
                .Add("LOS: Not Calculated")
                .Add("Size: Not Calculated")
                .Add("ZOC: Not Calculated")
            End With

            tvwPlacedItems.Nodes.Add(nod)
        Next

        'Dim key As String
        'For Each key In currentGame.AllChits.Keys
        '    ' put the item's name into the treeview
        '    Dim gc As cmplib01.GroundChitType = currentGame.AllChits(key)
        '    Dim nod As New TreeNode(gc.Name)

        '    If gc.OwningFaction = lstFactions.SelectedItem.factionid Then
        '        nod.ForeColor = System.Drawing.Color.DarkGreen
        '    Else
        '        nod.ForeColor = System.Drawing.Color.DarkRed
        '    End If

        '    nod.Nodes.Add("Type: " & gc.TypeName)
        '    nod.Nodes.Add("LOS: " & gc.LOS)
        '    nod.Nodes.Add("Size: " & gc.Size)
        '    nod.Nodes.Add("ZOC: " & gc.ZOCRange)

        '    tvwPlacedItems.Nodes.Add(nod)
        'Next

        ' deployment zones
        RefreshDeploymentZones()

    End Sub

    Private Sub RefreshDeploymentZones()
        Try
            lstDeploymentZones.Items.Clear()

            For Each key As String In currentGame.DeploymentZones_g.HT.Keys
                Dim dep As DeploymentZone = currentGame.DeploymentZones_g.Item(key)
                If dep.FactionID = lstFactions.SelectedItem.factionid Then
                    lstDeploymentZones.Items.Add(dep)
                End If
            Next

        Catch ex As Exception
            HandleException(c_Module & ".RefreshDeploymentZones", ex)
        End Try
    End Sub

    Private Sub ListBoundaries()
        lstBoundaries.Items.Clear()
        Dim bound As cmplib01.GenericBoundary
        For Each bound In currentGame.Boundaries
            lstBoundaries.Items.Add(bound)
        Next
    End Sub

    Private Sub ListAreaObjectives()
        lstObjectives.Items.Clear()
        Dim AO As AreaObjective
        For Each AO In currentGame.AreaObjectives
            lstObjectives.Items.Add(AO)
        Next
    End Sub

#Region "Placement"

    Private Sub PlaceGroundUnit(ByVal e As System.Windows.Forms.MouseEventArgs)
        '        If selectedItemKey.Substring(0, 4) = "OBJT" Then PlaceObjective(e)
        '       If selectedItemKey.Substring(0, 4) = "CHTT" Then PlaceUnit(e)
        'If selectedItemKey.Substring(0, 4) = "TOKT" Then PlaceToken(e)


        '// all we can currently deploy is objectives. 
        If TypeOf _selectedItem Is ObjectiveType Then PlaceObjective(e)
        '// the other types can go here


        ' after we add the new item, refresh the treeview, set the newly added item to selected (maybe)
        RefreshPlacedItemsTree()
        fmvMap.RedrawMap()

    End Sub

    Private Sub PlaceLocalDeploymentZone(ByVal e As System.Windows.Forms.MouseEventArgs)

    End Sub

    Private Sub PlaceObjective(ByVal e As System.Windows.Forms.MouseEventArgs)
        Try
            Dim mem As New InstallationChit
            mem.ptrInstallation = _selectedItem
            mem.OwningFaction = DirectCast(lstFactions.SelectedItem, Faction)
            Dim f As New frmTextEntry
            f.HeaderText = "Enter a name for this installation"
            f.InputText = mem.ptrInstallation.Name & " " & randy.Next(100, 999)
            f.StartPosition = FormStartPosition.CenterParent
            f.ShowDialog()

            If f.Cancelled = True Then Exit Sub

            mem.Name = f.InputText

            mem.Location = New Point(e.X, e.Y)
            mem.icon = _selectedItem.Icon(CampaignerGameData.CDGDIP_OWNER)

            Dim res As Resource
            For Each key As String In mem.ptrInstallation.ObjectiveResources.HT.Keys
                res = mem.ptrInstallation.ObjectiveResources.HT.Item(key)
                Dim rpoo As New ResourcePoolItem
                rpoo.resourceTypeptr = currentGame.ResourceTypes_g.Item(res.ResourceName)
                rpoo.accrueAmount = res.AccrueAmount
                rpoo.maxAmount = res.MaxAmount
                mem.Resources.add(rpoo)
            Next

            Dim rul As RuleType
            For Each rul In mem.ptrInstallation.GCRules
                Dim ru As New Rule
                ru.ptrRule = rul
                ru.usesRemaining = rul.MaxUses
                mem.chitRules.add(ru)
            Next

            currentGame.Chits.add(mem)
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

    End Sub

    Private Sub PlaceUnit(ByVal e As System.Windows.Forms.MouseEventArgs)
        'deprecated

        'Dim Unit As cmplib01.UnitType = currentGame.UnitTypes.Item(selectedItemKey)

        'Dim addUnit As cmplib01.UnitType

        '' clone and add
        'addUnit.Name = newUnit.TypeName & currentGame.AllChits.Count
        'Dim fact As cmplib01.Faction = lstFactions.SelectedItem
        'addUnit.OwningFaction = fact.FactionID

        'Dim pnt As New Point(e.X, e.Y)
        'addUnit.Location = pnt

        'Try
        '    currentGame.AllChits.Add(addUnit.Key & ":" & addUnit.Location.X & "-" & addUnit.Location.Y, addUnit)
        'Catch ex As System.ArgumentException

        'End Try

    End Sub

    Private Sub PlaceToken(ByVal e As System.Windows.Forms.MouseEventArgs)

    End Sub

#End Region

#Region "Selection"
    Private Function SelectAny(ByVal pnt As Point) As Boolean
        ' returns true if something was selected

    End Function

    Private Function SelectChit(ByVal pnt As Point) As Boolean
        ' returns true if a chit has been selected

        Try
            fmvMap.SelectChit(pnt)
            fmvMap.RedrawMap()
        Catch invalEx As InvalidCastException
            MessageBox.Show("You can't select Units in this version.", "Sorry.")
        Catch ex As Exception
            HandleException("CBuilder.SelectChit", ex)
        End Try

    End Function

    Private Function SelectDeploymentZone(ByVal pnt As Point) As Boolean
        ' returns true if a deploymentzone was selected

    End Function

    Private Function SelectMapFeature(ByVal pnt As Point) As Boolean
        ' returns true if a map feature has been selected

    End Function

#End Region

#Region "Free Drawing"
    Private Sub BeginNewPath(ByVal e As System.Windows.Forms.MouseEventArgs)

        deploymentZonePath = New Drawing2D.GraphicsPath()
        zonePathComplete = False
        zoneLastpoint.X = e.X
        zoneLastpoint.Y = e.Y

    End Sub

    Private Sub ContinuePath(ByVal e As System.Windows.Forms.MouseEventArgs)
        Dim pt As Point

        pt.X = e.X
        pt.Y = e.Y

        deploymentZonePath.AddLine(zoneLastpoint, pt)
        zoneLastpoint.X = e.X
        zoneLastpoint.Y = e.Y

        fmvMap.DrawFeaturePath(deploymentZonePath, Color.Red, Color.Green, 0)

    End Sub

    Private Sub ClosePath()

        ' close the path and then add the shape to the current feature.
        ' TODO: new way to close the path for closed areas.
        'deploymentZonePath.AddLine(deploymentZonePath.PathPoints(0), deploymentZonePath.PathPoints(deploymentZonePath.PathPoints.GetUpperBound(0)))
        deploymentZonePath.CloseFigure()

        zonePathComplete = True

        ' determine if this is a deployment zone, boundary or area objective
        Select Case PlacementMode
            Case Is = PlaceMode.FreeDeploy
                CloseDeploymentZone()
                RefreshDeploymentZones()
            Case Is = PlaceMode.GenericBoundary
                CloseGenericBoundary()
            Case Is = PlaceMode.AreaObjective
                CloseAreaObjective()
        End Select

    End Sub

    Private Sub CloseDeploymentZone()
        Dim newZone As New cmplib01.DeploymentZone()

        ' add one final line from the last point drawn to the first point.
        Dim fPoint As PointF = deploymentZonePath.PathPoints(0)
        Dim lPoint As PointF = deploymentZonePath.PathPoints(deploymentZonePath.PathPoints.GetUpperBound(0))
        deploymentZonePath.AddLine(lPoint, fPoint)

        newZone.BoundaryZone = True
        newZone.BoundaryPath = deploymentZonePath.PathData
        newZone.ZoneName = "New Free Zone"
        newZone.MaxDeploymentPerTurn = 1000
        newZone.MaxTotalDeploy = 3000
        newZone.Active = True
        newZone.Capturable = True
        newZone.CaptureEvent = cmplib01.CaptureEvent_cgd.Hold
        newZone.FactionID = currentGame.selectedFaction.FactionID
        ' show the data for this guy, like name, max points, which factions can use it, etc.
        Dim fDepZone As New frmDeploymentZone(newZone, currentGame)
        fDepZone.ShowDialog()

        ' add this guy to the deploymentzones
        Try
            If Not fDepZone.CancelPressed Then currentGame.DeploymentZones_g.Add(newZone, newZone.ZoneName)
            ' add the new zone to the list of deployment zones
            lstDeploymentZones.Items.Add(newZone)
        Catch ex As System.ArgumentException
            MessageBox.Show("Each Deployment Zone must have a unique name. This zone has not been added. Try again with a unique name.", "Invalid Name", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try
        ' redraw the map to show the new zone
        fmvMap.RedrawMap()

        ' change our last action
        stbStatus.Panels(1).Text = "Last Action: Deployment Zone (" & newZone.ZoneName & ") added."
    End Sub

    Private Sub CloseGenericBoundary()
        Dim newBound As New GenericBoundary()
        newBound.BoundaryName = "New Boundary"
        newBound.BoundaryDescription = "New Boundary"
        newBound.BoundaryPath = deploymentZonePath.PathData
        newBound.BoundaryStyle = Drawing.Drawing2D.DashStyle.Dash

        Try
            Dim fBoundProp As New frmNewGenericBoundary(newBound)
            fBoundProp.ShowDialog()
            If Not fBoundProp.Cancelled Then
                currentGame.Boundaries.Add(newBound)
            End If
            fmvMap.RedrawMap()
            stbStatus.Panels(1).Text = "Last Action: Boundary (" & newBound.BoundaryName & ") added."
            ListBoundaries()
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

    End Sub

    Private Sub CloseAreaObjective()
        Dim newAO As New AreaObjective()

        ' add one final line from the last point drawn to the first point.
        Dim fPoint As PointF = deploymentZonePath.PathPoints(0)
        Dim lPoint As PointF = deploymentZonePath.PathPoints(deploymentZonePath.PathPoints.GetUpperBound(0))
        deploymentZonePath.AddLine(lPoint, fPoint)

        newAO.BoundaryName = "New Area Objective"
        newAO.BoundaryDescription = "New Area Objective"
        newAO.BoundaryColor = Color.Black
        newAO.BoundaryStyle = Drawing.Drawing2D.DashStyle.Solid
        newAO.BoundaryWidth = 1
        newAO.OwningFaction = -1 'default to NONE NONE NONE
        newAO.BoundaryPath = deploymentZonePath.PathData
        Try
            Dim fAO As New frmNewAreaObjective(newAO, currentGame.Faction_g)
            fAO.ShowDialog()
            If Not fAO.Cancelled Then
                currentGame.AreaObjectives.Add(newAO)
                fmvMap.RedrawMap()
                ListAreaObjectives()
            End If
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try


    End Sub

    Private Sub EditDeploymentZone(ByRef item As DeploymentZone)
        Dim frmDep As New frmDeploymentZone(item, currentGame)
        frmDep.ShowDialog()
        RefreshDeploymentZoneTreeview()
    End Sub

    Private Sub DeleteDeploymentZone(ByRef item As DeploymentZone)
        ' removes the deploymentzone from the world of reality
        lstDeploymentZones.Items.Remove(item)
        currentGame.DeploymentZones_g.HT.Remove(item.ZoneName)
        fmvMap.RedrawMap()
        RefreshDeploymentZones()
    End Sub

    Private Sub RefreshDeploymentZoneTreeview()
        Dim key As String
        Dim depZ As DeploymentZone

        lstDeploymentZones.Items.Clear()

        For Each key In currentGame.DeploymentZones_g.HT.Keys
            depZ = currentGame.DeploymentZones_g.Item(key)
            If depZ.FactionID = currentGame.selectedFaction.FactionID Then
                lstDeploymentZones.Items.Add(depZ)
            End If
        Next

    End Sub

#End Region

#Region "Show Properties"
    Private Sub ShowObjectiveProperties(ByVal mem As InstallationChit) 'objective As ObjectiveType)
        ' populate the properties treeview with the rules and stuff for this guy

        Try
            tvwSelectedItemProperties.Nodes.Clear()
            tvwSelectedItemProperties.Nodes.Add("Name: " & mem.Name)
            tvwSelectedItemProperties.Nodes.Add("Type: " & mem.ptrInstallation.TypeName) ' objective.TypeName)
            tvwSelectedItemProperties.Nodes.Add("LOS: " & mem.ptrInstallation.LOS) ' objective.LOS)
            tvwSelectedItemProperties.Nodes.Add("LOS Power: " & mem.ptrInstallation.LOSPower) 'objective.LOSPower)
            tvwSelectedItemProperties.Nodes.Add("Size: " & mem.ptrInstallation.Size) 'objective.Size)
            tvwSelectedItemProperties.Nodes.Add("Uses ZOC: " & mem.ptrInstallation.UsesZOC.ToString) 'objective.UsesZOC.ToString)
            If mem.ptrInstallation.UsesZOC Then
                tvwSelectedItemProperties.Nodes.Add("ZOC: " & mem.ptrInstallation.ZOCRange)
            End If

            ' now put in rules and resources
            If mem.ptrInstallation.GCRules.Count <> 0 Then
                Dim ruleCol As New System.Windows.Forms.TreeNode("Rules")
                Dim rul As RuleType
                Dim colIndex As Byte

                For Each rul In mem.ptrInstallation.GCRules
                    Dim nod As New TreeNode()
                    nod.ForeColor = fmvMap.RuleColor(colIndex)
                    nod.Text = rul.RuleName
                    ruleCol.Nodes.Add(nod)
                    colIndex += 1
                    If colIndex = 11 Then colIndex = 0
                Next
                tvwSelectedItemProperties.Nodes.Add(ruleCol)
            End If

            If mem.ptrInstallation.ObjectiveResources.Count <> 0 Then
                Dim resCol As New System.Windows.Forms.TreeNode("Resources")
                Dim res As ResourcePoolItem

                For Each res In mem.Resources
                    Dim newnode As New TreeNode
                    newnode.Text = res.resourceTypeptr.ResourceName & " [" & res.localAmount & "/" & res.maxAmount & "] + " & res.accrueAmount
                    newnode.Tag = res
                    resCol.Nodes.Add(newnode)
                Next
                tvwSelectedItemProperties.Nodes.Add(resCol)
            End If

            pgdSelectedItemProperties.SelectedObject = mem

        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try
    End Sub

    Private Sub ShowDeploymentZoneProperties()

    End Sub

    Private Sub ShowMapFeatureProperties()

    End Sub

#End Region

#Region "Properties"

    Private Property GameDirty() As Boolean
        Get
            Return m_GameDirty
        End Get
        Set(ByVal Value As Boolean)
            m_GameDirty = Value
            ' we set the title after the value of dirty changes
            SetTitle()
        End Set
    End Property

    Private Property GameLoaded() As Boolean
        Get
            Return m_GameLoaded
        End Get
        Set(ByVal Value As Boolean)
            m_GameLoaded = Value
            If m_GameLoaded = True Then
                obdDefined.Enabled = True
                tlbMain.Buttons(c_SaveButton).Enabled = True
                tlbMain.Buttons(c_PlaceButton).Enabled = True
                tlbMain.Buttons(c_RemoveButton).Enabled = True
                tlbMain.Buttons(c_FreeDeployment).Enabled = True
                tlbMain.Buttons(c_LocalDeployment).Enabled = True
                tlbMain.Buttons(c_SelectChit).Enabled = True
                tlbMain.Buttons(c_SelectDeployment).Enabled = True
                tlbMain.Buttons(c_Boundary).Enabled = True
                tlbMain.Buttons(c_Objective).Enabled = True
                tlbMain.Buttons(c_VictoryConditions).Enabled = True
                tlbMain.Buttons(c_TemporaryLabel).Enabled = True
            Else
                ' if a game is not loaded, the map is always invalidated
                MapValidated = False
                ' disable the options for interacting with game parameters
                obdDefined.Enabled = False
                tlbMain.Buttons(c_SaveButton).Enabled = False
                tlbMain.Buttons(c_PlaceButton).Enabled = False
                tlbMain.Buttons(c_RemoveButton).Enabled = False
                tlbMain.Buttons(c_FreeDeployment).Enabled = False
                tlbMain.Buttons(c_LocalDeployment).Enabled = False
                tlbMain.Buttons(c_SelectChit).Enabled = False
                tlbMain.Buttons(c_SelectDeployment).Enabled = False
                tlbMain.Buttons(c_Boundary).Enabled = False
                tlbMain.Buttons(c_Objective).Enabled = False
                tlbMain.Buttons(c_TemporaryLabel).Enabled = False
            End If
        End Set
    End Property

    Private Property MapValidated() As Boolean
        Get
            Return m_MapValidated
        End Get
        Set(ByVal Value As Boolean)
            m_MapValidated = Value
        End Set
    End Property

    Private Property SelectionMode() As SelectMode
        Get
            Return m_selectionMode
        End Get
        Set(ByVal Value As SelectMode)
            m_selectionMode = Value
            Select Case m_selectionMode
                Case SelectMode.NoAction
                    tlbMain.Buttons(c_SelectChit).Pushed = False
                    tlbMain.Buttons(c_SelectDeployment).Pushed = False
                Case SelectMode.SelectChit
                    tlbMain.Buttons(c_PlaceButton).Pushed = False
                    PlacementMode = PlaceMode.SelectItem
                    tlbMain.Buttons(c_SelectChit).Pushed = True
                    tlbMain.Buttons(c_SelectDeployment).Pushed = False
                Case SelectMode.SelectDeployment
                    PlacementMode = PlaceMode.SelectItem
                    tlbMain.Buttons(c_SelectChit).Pushed = False
                    tlbMain.Buttons(c_SelectDeployment).Pushed = True
                    tlbMain.Buttons(c_FreeDeployment).Pushed = False
                    tlbMain.Buttons(c_PlaceButton).Pushed = False
            End Select
        End Set
    End Property

    Private Property PlacementMode() As PlaceMode
        Get
            Return m_placementMode
        End Get
        Set(ByVal Value As PlaceMode)
            m_placementMode = Value
            Select Case m_placementMode
                Case PlaceMode.NoAction
                    tlbMain.Buttons(c_PlaceButton).Pushed = False
                    tlbMain.Buttons(c_FreeDeployment).Pushed = False
                    tlbMain.Buttons(c_LocalDeployment).Pushed = False
                    tlbMain.Buttons(c_Boundary).Pushed = False
                    tlbMain.Buttons(c_Objective).Pushed = False
                    tlbMain.Buttons(c_TemporaryLabel).Pushed = False
                Case PlaceMode.Place
                    tlbMain.Buttons(c_PlaceButton).Pushed = True
                    tlbMain.Buttons(c_FreeDeployment).Pushed = False
                    tlbMain.Buttons(c_LocalDeployment).Pushed = False
                    tlbMain.Buttons(c_SelectChit).Pushed = False
                    tlbMain.Buttons(c_SelectDeployment).Pushed = False
                    tlbMain.Buttons(c_Boundary).Pushed = False
                    tlbMain.Buttons(c_Objective).Pushed = False
                    tlbMain.Buttons(c_TemporaryLabel).Pushed = False
                Case PlaceMode.FreeDeploy
                    tlbMain.Buttons(c_PlaceButton).Pushed = False
                    tlbMain.Buttons(c_FreeDeployment).Pushed = True
                    tlbMain.Buttons(c_LocalDeployment).Pushed = False
                    tlbMain.Buttons(c_SelectChit).Pushed = False
                    tlbMain.Buttons(c_SelectDeployment).Pushed = False
                    tlbMain.Buttons(c_Boundary).Pushed = False
                    tlbMain.Buttons(c_Objective).Pushed = False
                    tlbMain.Buttons(c_TemporaryLabel).Pushed = False
                Case PlaceMode.LocalDeploy
                    tlbMain.Buttons(c_PlaceButton).Pushed = False
                    tlbMain.Buttons(c_FreeDeployment).Pushed = False
                    tlbMain.Buttons(c_LocalDeployment).Pushed = True
                    tlbMain.Buttons(c_SelectChit).Pushed = False
                    tlbMain.Buttons(c_SelectDeployment).Pushed = False
                    tlbMain.Buttons(c_Boundary).Pushed = False
                    tlbMain.Buttons(c_Objective).Pushed = False
                    tlbMain.Buttons(c_TemporaryLabel).Pushed = False
                Case PlaceMode.GenericBoundary
                    tlbMain.Buttons(c_PlaceButton).Pushed = False
                    tlbMain.Buttons(c_FreeDeployment).Pushed = False
                    tlbMain.Buttons(c_LocalDeployment).Pushed = False
                    tlbMain.Buttons(c_SelectChit).Pushed = False
                    tlbMain.Buttons(c_SelectDeployment).Pushed = False
                    tlbMain.Buttons(c_Boundary).Pushed = True
                    tlbMain.Buttons(c_Objective).Pushed = False
                    tlbMain.Buttons(c_TemporaryLabel).Pushed = False
                Case PlaceMode.AreaObjective
                    tlbMain.Buttons(c_PlaceButton).Pushed = False
                    tlbMain.Buttons(c_FreeDeployment).Pushed = False
                    tlbMain.Buttons(c_LocalDeployment).Pushed = False
                    tlbMain.Buttons(c_SelectChit).Pushed = False
                    tlbMain.Buttons(c_SelectDeployment).Pushed = False
                    tlbMain.Buttons(c_Boundary).Pushed = False
                    tlbMain.Buttons(c_Objective).Pushed = True
                    tlbMain.Buttons(c_TemporaryLabel).Pushed = False
                Case PlaceMode.TemporaryMapLabel
                    tlbMain.Buttons(c_PlaceButton).Pushed = False
                    tlbMain.Buttons(c_FreeDeployment).Pushed = False
                    tlbMain.Buttons(c_LocalDeployment).Pushed = False
                    tlbMain.Buttons(c_SelectChit).Pushed = False
                    tlbMain.Buttons(c_SelectDeployment).Pushed = False
                    tlbMain.Buttons(c_Boundary).Pushed = False
                    tlbMain.Buttons(c_Objective).Pushed = False
                    tlbMain.Buttons(c_TemporaryLabel).Pushed = True
            End Select
        End Set
    End Property

#End Region

    Private Sub SetTitle()
        Me.Text = "CBuilder [" & currentGame.GameName & "]"
        If GameDirty Then
            Me.Text = Me.Text & " *"
        End If
    End Sub

    Private Sub lstFactions_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstFactions.SelectedIndexChanged
        currentGame.selectedFaction = lstFactions.SelectedItem
        fmvMap.RedrawMap() 'todo: chit selection
        RefreshPlacedItemsTree()
    End Sub

    Private Sub fmvMap_DisplayMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs) Handles fmvMap.DisplayMouseMove
        stbStatus.Panels(0).Text = Format(e.X, "0000") & ", " & Format(e.Y, "0000") & "  " & fmvMap.FMPData.TerrainNameAtCoord(New Point(e.X, e.Y))
    End Sub

    Private Sub btnShowRuleRange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowRuleRange.Click
        fmvMap.ShowSelectedObjectiveRuleRanges = Not fmvMap.ShowSelectedObjectiveRuleRanges
        If fmvMap.ShowSelectedObjectiveRuleRanges = True Then
            btnShowRuleRange.Text = "Hide Range"
        Else
            btnShowRuleRange.Text = "Rule Range"
        End If
    End Sub

    Private Sub btnDeleteObjective_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteObjective.Click
        DeleteSelectedObjective()
    End Sub

    Private Sub DeleteSelectedObjective()
        fmvMap.DeleteSelected()
        fmvMap.RedrawMap()
        RefreshPlacedItemsTree()
        tvwSelectedItemProperties.Nodes.Clear()
    End Sub

    Private Sub btnEditDeploymentZone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditDeploymentZone.Click
        If lstDeploymentZones.Items.Count = 0 Then Exit Sub
        If lstDeploymentZones.SelectedItem Is Nothing Then Exit Sub

        EditDeploymentZone(lstDeploymentZones.SelectedItem)

    End Sub

    Private Sub btnDeleteDeploymentZone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteDeploymentZone.Click
        If lstDeploymentZones.Items.Count = 0 Then Exit Sub
        If lstDeploymentZones.SelectedItem Is Nothing Then Exit Sub

        DeleteDeploymentZone(lstDeploymentZones.SelectedItem)
    End Sub

    Private Sub lstDeploymentZones_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstDeploymentZones.SelectedIndexChanged
        Try
            If fmvMap.SelectedDeploymentZone Is lstDeploymentZones.SelectedItem Then
                fmvMap.SelectedDeploymentZone = Nothing
                lstDeploymentZones.SelectedItem = Nothing
            Else
                fmvMap.SelectedDeploymentZone = lstDeploymentZones.SelectedItem
            End If

        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

    End Sub

    Private Sub mnuObjectiveType_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuObjectiveType.Click
        AddObjectiveType(currentGame, fmvMap.FMPData.MoveTypeLookup)
        obdDefined.ListItems()
    End Sub

    Private Sub mnuResourceType_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuResourceType.Click
        AddResource(currentGame)
        obdDefined.ListItems()
    End Sub

    Private Sub mnuRuleType_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuRuleType.Click
        AddRule(currentGame)
        obdDefined.ListItems()
    End Sub

    Private Sub mnuUnitType_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuUnitType.Click
        AddUnitType(currentGame, fmvMap.FMPData.MoveTypeLookup)
        obdDefined.ListItems()
    End Sub

    Private Sub mnuTokenType_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuTokenType.Click
        AddTokenType(currentGame, fmvMap.FMPData)
        obdDefined.ListItems()
    End Sub

    Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
        EditFactions(currentGame)
        PopulateFactionList()
    End Sub

    Private Sub mnuUserPlaceableDeploymentZone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuUserPlaceableDeploymentZone.Click
        ' this creates a new User-Placeable deployment zone. Thats all. It belongs to a faction.
        ' and its coming in the non-demo version. Hahaha!

    End Sub

    Private Sub mnuViewMapLabels_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuViewMapLabels.Click
        fmvMap.ShowLabels = Not fmvMap.ShowLabels
        mnuViewMapLabels.Checked = Not mnuViewMapLabels.Checked
        fmvMap.RedrawMap()
    End Sub

    Private Sub mnuViewLOSRanges_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuViewLOSRanges.Click
        fmvMap.ShowLOS = Not fmvMap.ShowLOS
        mnuViewLOSRanges.Checked = Not mnuViewLOSRanges.Checked
        fmvMap.RedrawMap()
    End Sub

    Private Sub mnuViewZOCRanges_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuViewZOCRanges.Click
        fmvMap.ShowZOC = Not fmvMap.ShowZOC
        mnuViewZOCRanges.Checked = Not mnuViewZOCRanges.Checked
        fmvMap.RedrawMap()
    End Sub

    Private Sub mnuMainEditor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuMainEditor.Click
        Dim MainEditor As New frmNewEmptyCampaign(currentGame)
        MainEditor.ShowDialog()
        obdDefined.ListItems()
        '// refresh da map, and set the proper game data
        fmvMap.RedrawMap()
        PopulateGameData()
    End Sub

    Private Sub mnuVictoryConditions_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuVictoryConditions.Click
        ShowVictoryConditions()
    End Sub

    Private Sub mnuImportTemplate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuImportTemplate.Click

        Try
            Dim opDiag As New OpenFileDialog
            opDiag.Filter = "Campaigner Games, Templates | *.cgd;*.cgt"
            opDiag.ShowDialog()

            Dim filepath As String = opDiag.FileName
            currentGame.ImportTemplate(filepath)
        Catch ex As Exception

        End Try

    End Sub

    Private Sub lstFactions_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lstFactions.MouseUp
        '        mnuPopie.Show(lstFactions, New Point(e.X, e.Y))
    End Sub


    Private Sub btnEditBoundary_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditBoundary.Click
        If lstBoundaries.SelectedItem Is Nothing Then Exit Sub

        Dim fBound As New frmNewGenericBoundary(lstBoundaries.SelectedItem)
        fBound.ShowDialog()

        If Not fBound.Cancelled Then
            fmvMap.RedrawMap()
            ListBoundaries()
        End If

    End Sub

    Private Sub btnDeleteBoundary_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteBoundary.Click
        If lstBoundaries.SelectedItem Is Nothing Then Exit Sub

        currentGame.Boundaries.Remove(lstBoundaries.SelectedItem)
        fmvMap.RedrawMap()
        ListBoundaries()

    End Sub

    Private Sub btnEditAreaObjective_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditAreaObjective.Click
        If lstObjectives.SelectedItem Is Nothing Then Exit Sub

        Dim fAO As New frmNewAreaObjective(lstObjectives.SelectedItem, currentGame.Faction_g)
        fAO.ShowDialog()
        If Not fAO.Cancelled Then
            fmvMap.RedrawMap()
            ListAreaObjectives()
        End If
    End Sub

    Private Sub btnDeleteAreaObjective_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteAreaObjective.Click
        If lstObjectives.SelectedItem Is Nothing Then Exit Sub

        currentGame.AreaObjectives.Remove(lstObjectives.SelectedItem)
        fmvMap.RedrawMap()
        ListAreaObjectives()
    End Sub


    Private Sub lstObjectives_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstObjectives.SelectedIndexChanged
        ' deselect currently selected item
        currentGame.AreaObjectives.DeselectAll()
        ' now set the selected property
        If lstObjectives.SelectedItem Is Nothing Then Exit Sub

        lstObjectives.SelectedItem.isselected = True
        fmvMap.RedrawMap()

    End Sub

    Private Sub lstBoundaries_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstBoundaries.SelectedIndexChanged
        ' deselect currently selected item
        currentGame.Boundaries.DeselectAll()
        ' set the selected one
        If lstBoundaries.SelectedItem Is Nothing Then Exit Sub

        lstBoundaries.SelectedItem.isselected = True
        fmvMap.RedrawMap()

    End Sub

    Private Sub ShowVictoryConditions()
        Dim fVC As New frmVictoryConditions(currentGame)
        fVC.ShowDialog()
    End Sub

    Private Sub mnuShowGrid_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuShowGrid.Click
        mnuShowGrid.Checked = Not mnuShowGrid.Checked
        If mnuShowGrid.Checked Then
            fmvMap.ShowGrid = True
            fmvMap.RedrawMap()
        Else
            fmvMap.ShowGrid = False
            fmvMap.RedrawMap()
        End If
    End Sub

    Private Sub mnuShowScale_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuShowScale.Click
        mnuShowScale.Checked = Not mnuShowScale.Checked
        If mnuShowScale.Checked = True Then
            fmvMap.ShowScale = True
            fmvMap.RedrawMap()
        Else
            fmvMap.ShowScale = False
            fmvMap.RedrawMap()
        End If
    End Sub

    Private Sub btnDeleteMapLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteMapLabel.Click
        If lstMapLabels.SelectedItem Is Nothing Then Exit Sub
        DeleteMapLabel(DirectCast(lstMapLabels.SelectedItem, CampaignerLabel))
    End Sub

    Private Sub DeleteMapLabel(ByRef cLab As CampaignerLabel)
        Try
            currentGame.cLabels.Remove(cLab)
            lstMapLabels.Items.Remove(lstMapLabels.SelectedItem)
            fmvMap.RedrawMap()
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try
    End Sub

    Private Sub DeleteMapLabel(ByRef mlab As FMPLib01.FlexMapData.MapLabel)
        ' we have to find the right maplabel... this could suck ballz.
        Try
            Dim gen As GenericProperty

            For Each gen In currentGame.ExtendedProperties
                If gen.PropertyName = "LabelType1" Then
                    Dim shit As New FMPLib01.FlexMapData.MapLabel()
                    shit.FromString(gen.PropertyValue)
                    If shit.text = mlab.text Then
                        ' this is the guy!
                        currentGame.ExtendedProperties.Remove(gen)
                        fmvMap.FMPData.TemporaryLabels.Remove(mlab)
                        ListTempLabels()
                        fmvMap.RedrawMap()
                        Exit For
                    End If
                End If
            Next
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

    End Sub

    Private Sub mnuNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuNew.Click
        NewGame()
    End Sub

    Private Sub mnuOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOpen.Click
        OpenGame()
    End Sub

    Private Sub mnuSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSave.Click
        SaveExistingGame()
    End Sub

    Private Sub tvwSelectedItemProperties_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvwSelectedItemProperties.AfterSelect
        If e.Node.Tag Is Nothing Then Exit Sub

        Try

            If TypeOf e.Node.Tag Is ResourcePoolItem Then
                Dim respoo As ResourcePoolItem = DirectCast(e.Node.Tag, ResourcePoolItem)
                Dim newamount As Integer = SetResourceInitialAmount(respoo)
                e.Node.Text = respoo.resourceTypeptr.ResourceName & "[" & respoo.localAmount & "/" & respoo.maxAmount & "] + " & respoo.accrueAmount
            End If
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try
    End Sub

    Private Function SetResourceInitialAmount(ByVal res As ResourcePoolItem) As Integer
        Try
            If fmvMap.SelectedChit Is Nothing Then Exit Function
            Dim amount As Integer = CInt(InputBox("Enter the starting amount of this resource type at this installation.", "Enter Amount"))

            Dim obj As InstallationChit = fmvMap.SelectedChit
            res.localAmount = amount
        Catch inval As InvalidCastException
            MessageBox.Show("You must select a numerical value.", "Enter a number")
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
    End Function

    Private Sub btnAdvancedProperties_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdvancedProperties.Click
        pgdSelectedItemProperties.Visible = Not pgdSelectedItemProperties.Visible

        If btnAdvancedProperties.Text = "Advanced" Then
            btnAdvancedProperties.Text = "Hide"
        Else
            btnAdvancedProperties.Text = "Advanced"
        End If

    End Sub

    Private Sub obdDefined_ItemSelected(ByRef obj As Object, ByRef objectType As cmplib01.CampaignerObjectType_cot) Handles obdDefined.ItemSelected
        If TypeOf obj Is GroundChitType Then
            _selectedItem = obj
        Else
            _selectedItem = Nothing
        End If
    End Sub

    Private Sub mnuModeratorPassword_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuModeratorPassword.Click
        Dim moder As Player
        Dim key As String
        Try

            For Each key In currentGame.Players.Keys
                moder = currentGame.Players.Item(key)
                If moder.PlayerName = "<Moderator>" Then Exit For
            Next

            'moder.Password' = InputBox("Enter a new password for the moderator.", "New Password")
            currentGame.ModeratorPassword = InputBox("Enter a new password for the moderator.", "New Password")
            moder.Password = currentGame.ModeratorPassword

        Catch ex As Exception
            MessageBox.Show("Player 'Moderator' is not available.")
        End Try
    End Sub

    Private Sub mnuPrereq_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuPrereq.Click
        Dim f As New frmPrerequisites
        f.GameData = currentGame
        f.ShowDialog()
    End Sub

    Private Sub mnuResourceConsumption_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuResourceConsumption.Click
        Dim f As New frmResourceConsumption()
        f.ShowDialog(currentGame, currentGame.selectedFaction)

    End Sub
End Class
